From 42dd99bfac9777a4ecc6700b87edf26a5c984de6 Mon Sep 17 00:00:00 2001 From: polwex Date: Wed, 23 Jul 2025 02:37:15 +0700 Subject: checkpoint --- src/openai.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/openai.ts') diff --git a/src/openai.ts b/src/openai.ts index 2e15dcf..12939bc 100644 --- a/src/openai.ts +++ b/src/openai.ts @@ -1,14 +1,8 @@ import fs from "fs"; import OpenAI from "openai"; import { RESPONSE_LENGTH } from "./logic/constants"; -import type { - AResult, - ChatMessage, - OChoice, - OChunk, - OMessage, - Result, -} from "./types"; +import type { ChatMessage, OChoice, OChunk, OMessage } from "./types"; +import type { AsyncRes, Result } from "sortug"; import OpenAIToolUse from "./openai_tools"; import type { FileObject } from "openai/src/resources/files.js"; @@ -26,7 +20,7 @@ export default class Conversation { private baseURL: string = "https://api.openai.com/v1"; private tokenizer: (text: string) => number = (text) => text.length / 3; openai; - private model: string = "chatgpt-4o-latest"; + private model: string = "gpt-4.1"; constructor(props: Props) { if (props.apiKey) this.apiKey = props.apiKey; @@ -56,7 +50,7 @@ export default class Conversation { }, []); } - public async send(sys: string, input: ChatMessage[]): AResult { + public async send(sys: string, input: ChatMessage[]): AsyncRes { const messages = this.mapMessages(input); const sysMsg: Message = { role: "system", content: sys }; const allMessages = [sysMsg, ...messages]; @@ -65,7 +59,7 @@ export default class Conversation { return res; } - public async sendR1(input: ChatMessage[]): AResult { + public async sendR1(input: ChatMessage[]): AsyncRes { const messages = this.mapMessagesR1(input); const truncated = this.truncateHistory(messages); const res = await this.apiCall(truncated); @@ -102,7 +96,7 @@ export default class Conversation { return messages; } - private async apiCall(messages: Message[]): AResult { + private async apiCall(messages: Message[]): AsyncRes { try { const completion = await this.openai.chat.completions.create({ temperature: 1.3, -- cgit v1.2.3