-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working convo logging to LangSmith, prompt engineering needs work
- Loading branch information
Showing
8 changed files
with
268 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// src/pages/api/chat.ts | ||
import { CourseMetadata } from '~/types/courseMetadata' | ||
import { getCourseMetadata } from '~/pages/api/UIUC-api/getCourseMetadata' | ||
// @ts-expect-error - no types | ||
import wasm from '../../../node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm?module' | ||
import tiktokenModel from '@dqbd/tiktoken/encoders/cl100k_base.json' | ||
import { Tiktoken, init } from '@dqbd/tiktoken/lite/init' | ||
import { OpenAIError, OpenAIStream } from '@/utils/server' | ||
import { | ||
ChatBody, | ||
Content, | ||
ContextWithMetadata, | ||
Conversation, | ||
MessageType, | ||
OpenAIChatMessage, | ||
ToolOutput, | ||
UIUCTool, | ||
} from '@/types/chat' | ||
import { NextResponse } from 'next/server' | ||
import { decrypt, isEncrypted } from '~/utils/crypto' | ||
import { buildPrompt } from './chat' | ||
|
||
export const config = { | ||
runtime: 'edge', | ||
} | ||
|
||
// A POST request endpoint that just calls buildPrompt and returns that as a json body. | ||
export default async (req: Request): Promise<NextResponse> => { | ||
try { | ||
const { conversation, key, course_name, courseMetadata, isImage } = | ||
(await req.json()) as ChatBody | ||
|
||
console.log('In build prompt fetch endpoint!!') | ||
|
||
const updatedConversation = await buildPrompt({ | ||
conversation, | ||
rawOpenaiKey: key, | ||
projectName: course_name, | ||
courseMetadata, | ||
isImage, | ||
}) | ||
|
||
return new NextResponse(JSON.stringify(updatedConversation)) | ||
} catch (error) { | ||
console.error('Error in buildPromptAPI:', error) | ||
return new NextResponse(JSON.stringify({ error: (error as Error).message })) | ||
} | ||
} |
Oops, something went wrong.