This repository has been archived by the owner on Jan 4, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: ChatGPT 4 claude
- Loading branch information
Showing
10 changed files
with
141 additions
and
16 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 |
---|---|---|
|
@@ -42,4 +42,4 @@ export async function copyClipboard(text: string) { | |
} catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
} |
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,66 @@ | ||
// code from sipc | ||
|
||
import axios from "axios"; | ||
import { getErrorMessage } from "@/pages/api/lib/utils"; | ||
|
||
export class ChatNio { | ||
public key: string; | ||
|
||
constructor(key: string) { | ||
this.key = key; | ||
} | ||
|
||
async translate( | ||
model: string, | ||
text: string, | ||
target: string, | ||
source: string = "auto", | ||
) { | ||
if (target === "classical-chinese") { | ||
target = "文言文"; | ||
if (source === "zh") { | ||
source = "白话文"; | ||
} | ||
} | ||
if (source === "classical-chinese") { | ||
source = "文言文"; | ||
if (target === "zh") { | ||
target = "白话文"; | ||
} | ||
} | ||
try { | ||
const headers = { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${this.key}`, | ||
}; | ||
const data = JSON.stringify({ | ||
model, | ||
messages: [ | ||
{ | ||
role: "system", | ||
content: `You are a professional, authentic translation engine, only returns translations.`, | ||
}, | ||
{ | ||
role: "user", | ||
content: `Please translate the text from ${source} to ${target} language,Translation will be enclosed within <start></end> tags, and they should not be included in the output.`, | ||
}, | ||
{ | ||
role: "user", | ||
content: `<start>${text}</end>`, | ||
}, | ||
], | ||
temperature: 0.7, | ||
}); | ||
const response = await axios.post( | ||
"https://api.chatnio.net/v1/chat/completions", | ||
data, | ||
{ headers }, | ||
); | ||
return response.data.choices[0].message.content; | ||
} catch (error) { | ||
throw new Error(`Error while translating: ${getErrorMessage(error)}`); | ||
} | ||
} | ||
} | ||
|
||
export const ChatNioInstance = new ChatNio(process.env.ChatNio_API_KEY!); |
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