diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/apis/gpt/GPT.ts | 33 | ||||
-rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx | 7 | ||||
-rw-r--r-- | src/client/views/nodes/DataVizBox/SchemaCSVPopUp.tsx | 4 |
3 files changed, 38 insertions, 6 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts index 6bde7989b..d1606e7f0 100644 --- a/src/client/apis/gpt/GPT.ts +++ b/src/client/apis/gpt/GPT.ts @@ -1,3 +1,5 @@ +import { config } from "dotenv"; +config(); import { Configuration, OpenAIApi } from 'openai'; enum GPTCallType { @@ -65,4 +67,33 @@ const gptImageCall = async (prompt: string, n?: number) => { } }; -export { gptAPICall, gptImageCall, GPTCallType }; +const gptCSVCall = async (inputText: string, callType: GPTCallType) => { + const opts: GPTCallOpts = callTypeMap[callType]; + try { + const configuration = new Configuration({ + apiKey: process.env.OPENAI_KEY, + }); + const openai = new OpenAIApi(configuration); + // const client = OpenAIApi; + // const response = await openai.createCompletion({ + // model: opts.model, + // max_tokens: opts.maxTokens, + // temperature: opts.temp, + // prompt: `${opts.prompt}${inputText}`, + // }); + // return response.data.choices[0].text; + + const responseGpt = await openai.createChatCompletion({ + model: "gpt-3.5-turbo-16k", + messages: [{role: "user", content: inputText}], + }) + const generatedResponse = responseGpt.data.choices[0].message?.content; + console.log(generatedResponse); + return generatedResponse; + } catch (err) { + console.log(err); + return 'Error connecting with API.'; + } +}; + +export { gptAPICall, gptImageCall, gptCSVCall, GPTCallType }; diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index 19689f972..3a1ea766a 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -1976,9 +1976,10 @@ ScriptingGlobals.add(function sendToBack(doc: Doc) { }); ScriptingGlobals.add(function datavizFromSchema(doc: Doc) { SelectionManager.Views().forEach(view => { - const keys = Cast(view.rootDoc.schema_columnKeys, listSpec('string'))?.filter(key => key!="text"); - - if (!keys) return; + var keys = Cast(view.layoutDoc.schema_columnKeys, listSpec('string'))?.filter(key => key!="text"); + const defaultColumnKeys: string[] = ['title', 'type', 'author', 'author_date']; + if (!keys) keys = Cast(view.layoutDoc.schema_columnKeys, listSpec('string'), defaultColumnKeys);; + const children = DocListCast(view.rootDoc[Doc.LayoutFieldKey(view.rootDoc)]); let csvRows = []; csvRows.push(keys.join(',')); diff --git a/src/client/views/nodes/DataVizBox/SchemaCSVPopUp.tsx b/src/client/views/nodes/DataVizBox/SchemaCSVPopUp.tsx index 0114721a2..309297307 100644 --- a/src/client/views/nodes/DataVizBox/SchemaCSVPopUp.tsx +++ b/src/client/views/nodes/DataVizBox/SchemaCSVPopUp.tsx @@ -55,9 +55,9 @@ export class SchemaCSVPopUp extends React.Component<SchemaCSVPopUpProps> { {this.heading('Schema Table as Data Visualization Doc')} <div className="image-content-wrapper"> <div className="img-wrapper"> - <div className="img-container" style={{background: "blue"}} onPointerDown={e => this.drag(e)}> + <div className="img-container" onPointerDown={e => this.drag(e)}> <img - width={150} height={150} + width={150} height={150} src={"/assets/dataVizBox.png"} /> </div> </div> |