You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// ChatCompletionStream orchestrates a streaming chat completion process with a language model (e.g., GPT), handling tool calls, message history management, and real-time streaming of responses to the client.
@@ -46,17 +55,20 @@ func (a *AIClientV2) ChatCompletionV2(ctx context.Context, modelSlug string, mes
46
55
// Returns: (same as ChatCompletion)
47
56
// 1. The full chat history sent to the language model (including any tool call results).
48
57
// 2. The incremental chat history visible to the user (including tool call results and assistant responses).
49
-
// 3. An error, if any occurred during the process. (However, in the streaming mode, the error is not returned, but sending by callbackStream)
58
+
// 3. Cost information (in USD, accumulated across all calls).
59
+
// 4. An error, if any occurred during the process. (However, in the streaming mode, the error is not returned, but sending by callbackStream)
50
60
//
51
61
// This function works as follows: (same as ChatCompletion)
52
62
// - It initializes the chat history for the language model and the user, and sets up a stream handler for real-time updates.
53
63
// - It repeatedly sends the current chat history to the language model, receives streaming responses, and forwards them to the client as they arrive.
54
64
// - If tool calls are required, it handles them and appends the results to the chat history, then continues the loop.
55
65
// - If no tool calls are needed, it appends the assistant's response and exits the loop.
56
-
// - Finally, it returns the updated chat histories and any error encountered.
// Bibliography is placed at the start of the prompt to leverage prompt caching
242
242
message:=fmt.Sprintf("Bibliography: %s\nSentence: %s\nBased on the sentence and bibliography, suggest only the most relevant citation keys separated by commas with no spaces (e.g. key1,key2). Be selective and only include citations that are directly relevant. Avoid suggesting more than 3 citations. If no relevant citations are found, return '%s'.", bibliography, sentence, emptyCitation)
0 commit comments