-
Notifications
You must be signed in to change notification settings - Fork 3
fix: update GraphQL mutation input type and clean up comments and add… #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
55f731d
f9b51a5
96eef24
8df0262
8912aa8
f9daff6
e135500
0090d22
fddbe0b
51728e2
75af9cb
cc4366a
38bb87f
2306999
f56ce7d
90df595
e4f66ec
464d0ea
57e4b23
e7b2935
f26d1d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -118,7 +118,7 @@ export class OpenAIModelProvider implements IModelProvider { | |||||||
let streamIterator: AsyncIterator<OpenAIChatCompletionChunk> | null = null; | ||||||||
const modelName = model || input.model; | ||||||||
const queue = this.getQueueForModel(modelName); | ||||||||
|
||||||||
let oldStreamValue: OpenAIChatCompletionChunk | null = null; | ||||||||
const createStream = async () => { | ||||||||
if (!stream) { | ||||||||
const result = await queue.add(async () => { | ||||||||
|
@@ -145,6 +145,9 @@ export class OpenAIModelProvider implements IModelProvider { | |||||||
const currentIterator = await createStream(); | ||||||||
const chunk = await currentIterator.next(); | ||||||||
const chunkValue = chunk.value as OpenAIChatCompletionChunk; | ||||||||
console.log('isDone:', chunk.done); | ||||||||
console.log('chunk:', chunk); | ||||||||
if (!chunk.done) oldStreamValue = chunkValue; | ||||||||
return { | ||||||||
done: chunk.done, | ||||||||
value: { | ||||||||
|
@@ -159,9 +162,23 @@ export class OpenAIModelProvider implements IModelProvider { | |||||||
} | ||||||||
}, | ||||||||
async return() { | ||||||||
console.log(stream); | ||||||||
console.log(streamIterator); | ||||||||
console.log('return() called'); | ||||||||
Comment on lines
+165
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove debugging console logs before merging These console logs should be removed before merging to production. - console.log(stream);
- console.log(streamIterator);
- console.log('return() called'); 📝 Committable suggestion
Suggested change
|
||||||||
stream = null; | ||||||||
streamIterator = null; | ||||||||
return { done: true, value: undefined }; | ||||||||
return { | ||||||||
done: true, | ||||||||
value: { | ||||||||
...oldStreamValue, | ||||||||
status: StreamStatus.DONE, | ||||||||
choices: [ | ||||||||
{ | ||||||||
finishReason: 'stop', | ||||||||
}, | ||||||||
], | ||||||||
}, | ||||||||
}; | ||||||||
}, | ||||||||
async throw(error) { | ||||||||
stream = null; | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,71 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { ChatInputType } from '@/graphql/type'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export const startChatStream = async ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
input: ChatInputType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
token: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
stream: boolean = false // Default to non-streaming for better performance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): Promise<string> => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!token) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw new Error('Not authenticated'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { chatId, message, model } = input; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const response = await fetch('/api/chat', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
method: 'POST', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'Content-Type': 'application/json', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Authorization: `Bearer ${token}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
body: JSON.stringify({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chatId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
message, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
stream, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+12
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing role parameter in API request. The function doesn't include the body: JSON.stringify({
chatId,
message,
model,
+ role: input.role,
stream,
}), 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!response.ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw new Error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
`Network response was not ok: ${response.status} ${response.statusText}` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: Handle streaming responses properly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// if (stream) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// // For streaming responses, aggregate the streamed content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// let fullContent = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// const reader = response.body?.getReader(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// if (!reader) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// throw new Error('No reader available'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// while (true) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// const { done, value } = await reader.read(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// if (done) break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// const text = new TextDecoder().decode(value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// const lines = text.split('\n\n'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// for (const line of lines) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// if (line.startsWith('data: ')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// const data = line.slice(5); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// if (data === '[DONE]') break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// const { content } = JSON.parse(data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// if (content) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// fullContent += content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// console.error('Error parsing SSE data:', e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// return fullContent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// // For non-streaming responses, return the content directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// const data = await response.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// return data.content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const data = await response.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return data.content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove debugging console logs before merging
These console logs appear to be debugging statements that should be removed before merging to production. They could potentially log sensitive information and will clutter the console.
📝 Committable suggestion