Skip to content

Add LLM improvements #3010

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

Merged
merged 14 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions src/features/sicp/chatCompletion/api.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Tokens } from 'src/commons/application/types/SessionTypes';
import { request } from 'src/commons/utils/RequestHelper';

/**
* POST /chat
*/
export async function chat(
export async function initChat(
tokens: Tokens,
payload: { role: string; content: string }[]
): Promise<string> {
const response = await request(`chat`, 'POST', {
section: string,
textBookContent: string
): Promise<InitChatResponse> {
const response = await request('chats', 'POST', {
...tokens,
body: { json: payload }
body: { section: section, initialContext: textBookContent }
});
if (!response) {
throw new Error('Unknown error occurred.');
Expand All @@ -19,5 +17,24 @@ export async function chat(
const message = await response.text();
throw new Error(`Failed to chat to louis: ${message}`);
}
return response.text();
return await response.json();
}

export async function continueChat(
tokens: Tokens,
chatId: string,
userMessage: string
): Promise<ContinueChatResponse> {
const response = await request(`chats/${chatId}/message`, 'POST', {
...tokens,
body: { message: userMessage }
});
if (!response) {
throw new Error('Unknown error occurred.');
}
if (!response.ok) {
const message = await response.text();
throw new Error(`Failed to chat to louis: ${message}`);
}
return await response.json();
}
Loading
Loading