summaryrefslogtreecommitdiff
path: root/src/openai.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/openai.ts')
-rw-r--r--src/openai.ts18
1 files changed, 6 insertions, 12 deletions
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<OChoice[]> {
+ public async send(sys: string, input: ChatMessage[]): AsyncRes<OChoice[]> {
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<OChoice[]> {
+ public async sendR1(input: ChatMessage[]): AsyncRes<OChoice[]> {
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<OChoice[]> {
+ private async apiCall(messages: Message[]): AsyncRes<OChoice[]> {
try {
const completion = await this.openai.chat.completions.create({
temperature: 1.3,