Skip to content

Commit

Permalink
feat: add API model preference maybe relate to #2
Browse files Browse the repository at this point in the history
  • Loading branch information
douo committed Mar 23, 2023
1 parent 4100a4e commit a666ecf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,40 @@
"default": "https://api.openai.com/v1/chat/completions",
"required": true
},
{
"name": "apiModel",
"type": "dropdown",
"required": false,
"title": "API Model",
"default": "gpt-3.5-turbo",
"description": "Choice API Model",
"data": [
{
"value": "gpt-3.5-turbo",
"title": "gpt-3.5-turbo"
},
{
"value": "gpt-3.5-turbo-0301",
"title": "gpt-3.5-turbo-0301"
},
{
"value": "gpt-4",
"title": "gpt-4"
},
{
"value": "gpt-4-0314",
"title": "gpt-4-0314"
},
{
"value": "gpt-4-32k",
"title": "gpt-4-32k"
},
{
"value": "gpt-4-32k-0314",
"title": "gpt-4-32k-0314"
}
]
},
{
"name": "toLang",
"type": "dropdown",
Expand Down
4 changes: 2 additions & 2 deletions src/providers/openai/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface TranslateResult {

const chineseLangs = ["zh", "zh-CN", "zh-TW", "zh-Hans", "zh-Hant", "wyw", "yue"];

export async function translate(query: TranslateQuery, entrypoint: string, apiKey: string) {
export async function translate(query: TranslateQuery, entrypoint: string, apiKey: string, model: string) {
const headers: Record<string, string> =
apiKey == "none"
? { "Content-Type": "application/json" }
Expand Down Expand Up @@ -82,7 +82,7 @@ export async function translate(query: TranslateQuery, entrypoint: string, apiKe
break;
}
const body = {
model: "gpt-3.5-turbo",
model,
temperature: 0,
max_tokens: 1000,
top_p: 1,
Expand Down
5 changes: 2 additions & 3 deletions src/views/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export const ContentView = (props: ContentViewProps) => {
const [data, setData] = useState<ViewItem[]>();
const [querying, setQuerying] = useState<Querying | null>();
const [translatedText, setTranslatedText] = useState("");
const { entrypoint, apikey } = getPreferenceValues<{ entrypoint: string; apikey: string }>();

const { entrypoint, apikey, apiModel } = getPreferenceValues<{ entrypoint: string; apikey: string; apiModel: string }>();
const ref = useRef<string>();
function updateData() {
if (history.data) {
Expand Down Expand Up @@ -157,7 +156,7 @@ export const ContentView = (props: ContentViewProps) => {
setTranslatedText("");
setQuerying(_querying);
query.updateText("");
translate(_querying.query, entrypoint, apikey);
translate(_querying.query, entrypoint, apikey, apiModel);
}

useEffect(() => {
Expand Down

0 comments on commit a666ecf

Please sign in to comment.