forked from phoenix-oss/llama-stack-mirror
LocalInferenceImpl update for LS 0.1 (#911)
# What does this PR do? To work with the updated iOSCalendarAssistantWithLocalInf [here](https://github.com/meta-llama/llama-stack-apps/compare/ios_local). In short, provide a summary of what this PR does and why. Usually, the relevant context should be present in a linked issue. - [ ] Addresses issue (#issue) ## Test Plan Please describe: - tests you ran to verify your changes with result summaries. - provide instructions so it can be reproduced. ## Sources Please link relevant resources if necessary. ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [ ] Ran pre-commit to handle lint / formatting issues. - [ ] Read the [contributor guideline](https://github.com/meta-llama/llama-stack/blob/main/CONTRIBUTING.md), Pull Request section? - [ ] Updated relevant documentation. - [ ] Wrote necessary unit or integration tests.
This commit is contained in:
parent
7fdbd5b642
commit
587753da2f
2 changed files with 53 additions and 37 deletions
|
@ -40,7 +40,7 @@ public class LocalInference: Inference {
|
|||
|
||||
public func chatCompletion(request: Components.Schemas.ChatCompletionRequest) -> AsyncStream<Components.Schemas.ChatCompletionResponseStreamChunk> {
|
||||
return AsyncStream { continuation in
|
||||
runnerQueue.async {
|
||||
let workItem = DispatchWorkItem {
|
||||
do {
|
||||
var tokens: [String] = []
|
||||
|
||||
|
@ -69,9 +69,10 @@ public class LocalInference: Inference {
|
|||
continuation.yield(
|
||||
Components.Schemas.ChatCompletionResponseStreamChunk(
|
||||
event: Components.Schemas.ChatCompletionResponseEvent(
|
||||
delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
|
||||
content: .case1(""),
|
||||
parse_status: Components.Schemas.ToolCallParseStatus.started
|
||||
delta: .tool_call(Components.Schemas.ToolCallDelta(
|
||||
parse_status: Components.Schemas.ToolCallParseStatus.started,
|
||||
tool_call: .case1(""),
|
||||
_type: Components.Schemas.ToolCallDelta._typePayload.tool_call
|
||||
)
|
||||
),
|
||||
event_type: .progress
|
||||
|
@ -95,14 +96,18 @@ public class LocalInference: Inference {
|
|||
text = token
|
||||
}
|
||||
|
||||
var delta: Components.Schemas.ChatCompletionResponseEvent.deltaPayload
|
||||
var delta: Components.Schemas.ContentDelta
|
||||
if ipython {
|
||||
delta = .ToolCallDelta(Components.Schemas.ToolCallDelta(
|
||||
content: .case1(text),
|
||||
parse_status: .in_progress
|
||||
delta = .tool_call(Components.Schemas.ToolCallDelta(
|
||||
parse_status: .in_progress,
|
||||
tool_call: .case1(text),
|
||||
_type: .tool_call
|
||||
))
|
||||
} else {
|
||||
delta = .case1(text)
|
||||
delta = .text(Components.Schemas.TextDelta(
|
||||
text: text,
|
||||
_type: Components.Schemas.TextDelta._typePayload.text)
|
||||
)
|
||||
}
|
||||
|
||||
if stopReason == nil {
|
||||
|
@ -129,7 +134,12 @@ public class LocalInference: Inference {
|
|||
continuation.yield(
|
||||
Components.Schemas.ChatCompletionResponseStreamChunk(
|
||||
event: Components.Schemas.ChatCompletionResponseEvent(
|
||||
delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(content: .case1(""), parse_status: .failure)),
|
||||
delta: .tool_call(Components.Schemas.ToolCallDelta(
|
||||
parse_status: Components.Schemas.ToolCallParseStatus.failed,
|
||||
tool_call: .case1(""),
|
||||
_type: Components.Schemas.ToolCallDelta._typePayload.tool_call
|
||||
)
|
||||
),
|
||||
event_type: .progress
|
||||
)
|
||||
// TODO: stopReason
|
||||
|
@ -141,10 +151,12 @@ public class LocalInference: Inference {
|
|||
continuation.yield(
|
||||
Components.Schemas.ChatCompletionResponseStreamChunk(
|
||||
event: Components.Schemas.ChatCompletionResponseEvent(
|
||||
delta: .ToolCallDelta(Components.Schemas.ToolCallDelta(
|
||||
content: .ToolCall(toolCall),
|
||||
parse_status: .success
|
||||
)),
|
||||
delta: .tool_call(Components.Schemas.ToolCallDelta(
|
||||
parse_status: Components.Schemas.ToolCallParseStatus.succeeded,
|
||||
tool_call: Components.Schemas.ToolCallDelta.tool_callPayload.ToolCall(toolCall),
|
||||
_type: Components.Schemas.ToolCallDelta._typePayload.tool_call
|
||||
)
|
||||
),
|
||||
event_type: .progress
|
||||
)
|
||||
// TODO: stopReason
|
||||
|
@ -155,7 +167,10 @@ public class LocalInference: Inference {
|
|||
continuation.yield(
|
||||
Components.Schemas.ChatCompletionResponseStreamChunk(
|
||||
event: Components.Schemas.ChatCompletionResponseEvent(
|
||||
delta: .case1(""),
|
||||
delta: .text(Components.Schemas.TextDelta(
|
||||
text: "",
|
||||
_type: Components.Schemas.TextDelta._typePayload.text)
|
||||
),
|
||||
event_type: .complete
|
||||
)
|
||||
// TODO: stopReason
|
||||
|
@ -166,6 +181,7 @@ public class LocalInference: Inference {
|
|||
print("Inference error: " + error.localizedDescription)
|
||||
}
|
||||
}
|
||||
runnerQueue.async(execute: workItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue