From 88caa55967b1dbf670b156dd08efc4f559067af7 Mon Sep 17 00:00:00 2001 From: srichman333 Date: Mon, 19 Feb 2024 16:19:05 -0500 Subject: ai (updates from sophie, then added dataviz summary) --- src/client/apis/gpt/GPT.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/client/apis/gpt/GPT.ts') diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts index cea862330..a0de6fa1f 100644 --- a/src/client/apis/gpt/GPT.ts +++ b/src/client/apis/gpt/GPT.ts @@ -1,9 +1,11 @@ import { ClientOptions, OpenAI } from 'openai'; +import { ChatCompletionMessageParam } from 'openai/resources'; enum GPTCallType { SUMMARY = 'summary', COMPLETION = 'completion', EDIT = 'edit', + DATA = 'data', } type GPTCallOpts = { @@ -13,10 +15,16 @@ type GPTCallOpts = { prompt: string; }; +/** + * Replace completions (deprecated) with chat + */ + const callTypeMap: { [type: string]: GPTCallOpts } = { - summary: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: 'Summarize this text in simpler terms: ' }, - edit: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: 'Reword this: ' }, - completion: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: '' }, + // newest model: gpt-4 + summary: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: 'Summarize the text given in simpler terms.' }, + edit: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: 'Reword the text.' }, + completion: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: "You are a helpful assistant. Answer the user's prompt." }, + data: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: "You are a helpful assistant. Analyze the user's data." }, }; /** @@ -34,13 +42,20 @@ const gptAPICall = async (inputText: string, callType: GPTCallType) => { dangerouslyAllowBrowser: true, }; const openai = new OpenAI(configuration); - const response = await openai.completions.create({ + + let messages: ChatCompletionMessageParam[] = [ + { role: 'system', content: opts.prompt }, + { role: 'user', content: inputText }, + ]; + + const response = await openai.chat.completions.create({ model: opts.model, - max_tokens: opts.maxTokens, + messages: messages, temperature: opts.temp, - prompt: `${opts.prompt}${inputText}`, + max_tokens: opts.maxTokens, }); - return response.choices[0].text; + const content = response.choices[0].message.content; + return content; } catch (err) { console.log(err); return 'Error connecting with API.'; @@ -60,8 +75,7 @@ const gptImageCall = async (prompt: string, n?: number) => { n: n ?? 1, size: '1024x1024', }); - return response.data.map((data: any) => data.url); - // return response.data.data[0].url; + return response.data.map(data => data.url); } catch (err) { console.error(err); return; -- cgit v1.2.3-70-g09d2 From 9f2f3875e5bf1b9f8058001d45918208d5ea820a Mon Sep 17 00:00:00 2001 From: srichman333 Date: Wed, 21 Feb 2024 21:40:26 -0500 Subject: updated prompt --- src/.DS_Store | Bin 10244 -> 10244 bytes src/client/apis/gpt/GPT.ts | 2 +- src/client/views/pdf/GPTPopup/GPTPopup.tsx | 3 +++ 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/client/apis/gpt/GPT.ts') diff --git a/src/.DS_Store b/src/.DS_Store index c363efb13..21ad8bd73 100644 Binary files a/src/.DS_Store and b/src/.DS_Store differ diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts index a0de6fa1f..82436c42b 100644 --- a/src/client/apis/gpt/GPT.ts +++ b/src/client/apis/gpt/GPT.ts @@ -24,7 +24,7 @@ const callTypeMap: { [type: string]: GPTCallOpts } = { summary: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: 'Summarize the text given in simpler terms.' }, edit: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: 'Reword the text.' }, completion: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: "You are a helpful assistant. Answer the user's prompt." }, - data: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: "You are a helpful assistant. Analyze the user's data." }, + data: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: "You are a helpful resarch assistant. Analyze the user's data to find meaningful patterns and/or correlation. Please keep your response short and to the point" }, }; /** diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx index 6e5f48a2f..a14c659db 100644 --- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx +++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx @@ -269,7 +269,10 @@ export class GPTPopup extends ObservableReactComponent {
{this.done ? ( <> + {this.mode==GPTPopupMode.SUMMARY? } color={StrCast(Doc.UserDoc().userVariantColor)} /> + : null } + {/* } color={StrCast(Doc.UserDoc().userVariantColor)} /> */}
{!this.loading && (
- {this.done ? ( + {this.done? + this.chatMode?( + { + e.key === 'Enter' ? this.generateDataAnalysis() : null; + e.stopPropagation(); + }} + type="text" + placeholder="Ask GPT a question about the data..." + id="search-input" + className="searchBox-input" + style={{width: "100%"}} + /> + ) + :( <>
)} -- cgit v1.2.3-70-g09d2 From 90183d3c7315d5fc88d2653937c5b59309a79b0e Mon Sep 17 00:00:00 2001 From: srichman333 Date: Wed, 28 Feb 2024 23:41:36 -0500 Subject: better prompt for custom questions + summary bug fix --- src/client/apis/gpt/GPT.ts | 4 ++-- src/client/views/pdf/AnchorMenu.tsx | 1 - src/client/views/pdf/GPTPopup/GPTPopup.tsx | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/client/apis/gpt/GPT.ts') diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts index 97a332294..c97d29d6f 100644 --- a/src/client/apis/gpt/GPT.ts +++ b/src/client/apis/gpt/GPT.ts @@ -24,7 +24,7 @@ const callTypeMap: { [type: string]: GPTCallOpts } = { summary: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: 'Summarize the text given in simpler terms.' }, edit: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: 'Reword the text.' }, completion: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: "You are a helpful assistant. Answer the user's prompt." }, - data: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: "You are a helpful resarch assistant. Analyze the user's data to find meaningful patterns and/or correlation. Please keep your response short and to the point" }, + data: { model: 'gpt-3.5-turbo', maxTokens: 256, temp: 0.5, prompt: "You are a helpful resarch assistant. Analyze the user's data to find meaningful patterns and/or correlation. Please keep your response short and to the point." }, }; /** @@ -43,7 +43,7 @@ const gptAPICall = async (inputText: string, callType: GPTCallType, prompt?: any }; const openai = new OpenAI(configuration); - let usePrompt = prompt? prompt: opts.prompt; + let usePrompt = prompt? opts.prompt+prompt: opts.prompt; let messages: ChatCompletionMessageParam[] = [ { role: 'system', content: usePrompt }, { role: 'user', content: inputText }, diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx index 222cf2f7e..74efb972c 100644 --- a/src/client/views/pdf/AnchorMenu.tsx +++ b/src/client/views/pdf/AnchorMenu.tsx @@ -6,7 +6,6 @@ import * as React from 'react'; import { ColorResult } from 'react-color'; import { Utils, returnFalse, setupMoveUpEvents, unimplementedFunction } from '../../../Utils'; import { Doc, Opt } from '../../../fields/Doc'; -import { GPTCallType, gptAPICall } from '../../apis/gpt/GPT'; import { DocumentType } from '../../documents/DocumentTypes'; import { SelectionManager } from '../../util/SelectionManager'; import { SettingsManager } from '../../util/SettingsManager'; diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx index 6301721e8..5f399e86a 100644 --- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx +++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx @@ -395,7 +395,7 @@ export class GPTPopup extends ObservableReactComponent { render() { return (
- {(this.mode === GPTPopupMode.SUMMARY? this.summaryBox() : this.mode === GPTPopupMode.DATA)? this.dataAnalysisBox() : this.mode === GPTPopupMode.IMAGE ? this.imageBox() : <>} + {this.mode === GPTPopupMode.SUMMARY? this.summaryBox() : this.mode === GPTPopupMode.DATA? this.dataAnalysisBox() : this.mode === GPTPopupMode.IMAGE ? this.imageBox() : <>}
); } -- cgit v1.2.3-70-g09d2 From d20746762917fd0378f731fd06e26567dde9e486 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 24 Apr 2024 18:36:52 -0400 Subject: minor tweaks for merging --- src/client/apis/gpt/GPT.ts | 6 +++--- src/client/views/nodes/formattedText/FormattedTextBox.tsx | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'src/client/apis/gpt/GPT.ts') diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts index c97d29d6f..30194f9f8 100644 --- a/src/client/apis/gpt/GPT.ts +++ b/src/client/apis/gpt/GPT.ts @@ -43,7 +43,7 @@ const gptAPICall = async (inputText: string, callType: GPTCallType, prompt?: any }; const openai = new OpenAI(configuration); - let usePrompt = prompt? opts.prompt+prompt: opts.prompt; + let usePrompt = prompt ? opts.prompt + prompt : opts.prompt; let messages: ChatCompletionMessageParam[] = [ { role: 'system', content: usePrompt }, { role: 'user', content: inputText }, @@ -51,9 +51,9 @@ const gptAPICall = async (inputText: string, callType: GPTCallType, prompt?: any const response = await openai.chat.completions.create({ model: opts.model, - messages: messages, - temperature: opts.temp, max_tokens: opts.maxTokens, + temperature: opts.temp, + messages, }); const content = response.choices[0].message.content; return content; diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index bb910737b..36c1de841 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -984,13 +984,10 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent { - if (!this._editorView) return; if (resIndex < newText.length) { - const marks = this._editorView.state.storedMarks ?? []; - this._editorView.dispatch(this._editorView.state.tr.insertText(newText[resIndex]).setStoredMarks(marks)); - setTimeout(() => { - this.animateRes(resIndex + 1, newText); - }, 20); + const marks = this._editorView?.state.storedMarks ?? []; + this._editorView?.dispatch(this._editorView?.state.tr.insertText(newText[resIndex]).setStoredMarks(marks)); + setTimeout(() => this.animateRes(resIndex + 1, newText), 20); } }; -- cgit v1.2.3-70-g09d2