Public Access
fix: add type annotation for ChatCompletionMessageParam in getHint and tutorChat functions
This commit is contained in:
1 parent
54a0ede92a
commit
152a805961
2 files changed
+6
-5
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { z } from 'zod'
|
||||
import { getAIClient, getAIModelForTask } from './aiClient.js'
|
||||
import { AiUsageResult, estimateTokensFromMessages, estimateTokensFromText, estimateTotalTokens, resolveUsageTokens } from '../utils/aiTokens.js'
|
||||
import type { ChatCompletionMessageParam } from 'openai/resources/index.js'
|
||||
|
||||
export type QuestionType =
|
||||
| 'multiple-choice'
|
||||
@@ -234,7 +235,7 @@ export async function getHint(req: HintRequest): Promise<AiUsageResult<{ hint: s
|
||||
const safeQuestion = stripAnswerFields(req.question)
|
||||
const model = getAIModelForTask('hint')
|
||||
|
||||
const messages = [
|
||||
const messages: ChatCompletionMessageParam[] = [
|
||||
{
|
||||
role: 'system',
|
||||
content: `You are a tutor helping a student during an exam. Give exactly one short hint (1-2 sentences) in ${req.language} that nudges the student toward the right approach. Never reveal the answer, never restate the answer in different words, and never give the answer to a multiple-choice option. Focus on the concept or strategy. Respond ONLY with a JSON object: { "hint": string }.`,
|
||||
@@ -245,7 +246,7 @@ export async function getHint(req: HintRequest): Promise<AiUsageResult<{ hint: s
|
||||
},
|
||||
]
|
||||
|
||||
const promptTokens = estimateTokensFromMessages(messages)
|
||||
const promptTokens = estimateTokensFromMessages(messages as Array<{ content: string }>)
|
||||
const estimatedTokens = estimateTotalTokens(promptTokens, 160)
|
||||
|
||||
const completion = await client.chat.completions.create({
|
||||
@@ -315,11 +316,11 @@ Exam (JSON): ${JSON.stringify(req.exam).slice(0, 8000)}
|
||||
|
||||
Student's submission state (answers, flags, etc., JSON): ${JSON.stringify(req.state).slice(0, 4000)}`
|
||||
|
||||
const messages = [
|
||||
const messages: ChatCompletionMessageParam[] = [
|
||||
{ role: 'system', content: systemPrompt },
|
||||
...recent.map((m) => ({ role: m.role, content: m.content })),
|
||||
]
|
||||
const promptTokens = estimateTokensFromMessages(messages)
|
||||
const promptTokens = estimateTokensFromMessages(messages as Array<{ content: string }>)
|
||||
const estimatedTokens = estimateTotalTokens(promptTokens, 600)
|
||||
|
||||
const completion = await client.chat.completions.create({
|
||||
|
||||
@@ -10,7 +10,7 @@ export interface JwtPayload {
|
||||
}
|
||||
|
||||
export function signToken(payload: JwtPayload): string {
|
||||
return jwt.sign(payload, config.jwtSecret, { expiresIn: config.jwtExpiresIn })
|
||||
return jwt.sign(payload, config.jwtSecret, { expiresIn: config.jwtExpiresIn } as jwt.SignOptions)
|
||||
}
|
||||
|
||||
export function verifyToken(token: string): JwtPayload {
|
||||
|
||||
Reference in new issue
Block a user