Skip to content

Commit

Permalink
Add Method call returns response without streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Wang committed May 9, 2024
1 parent 6add0a7 commit dc8887c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ and the purpose of this repo is to provide a swiftier API for Swift developers.

## Install

.package(url: "https://github.com/ShenghaiWang/SwiftLlama.git", from: "0.1.0")
.package(url: "https://github.com/ShenghaiWang/SwiftLlama.git", from: "0.2.0")

## Usage

### 1 Initialise swiftLlama using model path.

let swiftLlama = try SwiftLlama(modelPath: path))

### 2 Call it
### 2 Call it

#### Using AsyncStream method
### Call without streaming

let response: String = try await swiftLlama.start(for: prompt)

#### Using AsyncStream for streaming

for try await value in await swiftLlama.start(for: prompt) {
result += value
}

#### Using Combine publisher
#### Using Combine publisher for streaming

await swiftLlama.start(for: prompt)
.sink { _ in
Expand Down
9 changes: 9 additions & 0 deletions Sources/SwiftLlama/Swiftllama.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,13 @@ public class SwiftLlama {
}
return resultSubject.eraseToAnyPublisher()
}

@SwiftLlamaActor
public func start(for prompt: Prompt, sessionSupport: Bool = false) async throws -> String {
var result = ""
for try await value in await start(for: prompt) {
result += value
}
return result
}
}

0 comments on commit dc8887c

Please # to comment.