diff options
author | srichman333 <sarah_n_richman@brown.edu> | 2024-04-16 00:44:43 -0400 |
---|---|---|
committer | srichman333 <sarah_n_richman@brown.edu> | 2024-04-16 00:44:43 -0400 |
commit | 982991ca69cd7f844680949ed160e678f89050fc (patch) | |
tree | d205fb7061ce891cbd5b11bf4b809788b4abda69 /src | |
parent | c254b38690e27b32d3ac6316af9bb37d6d3e86aa (diff) |
correlation from gpt
Diffstat (limited to 'src')
-rw-r--r-- | src/client/apis/gpt/GPT.ts | 4 | ||||
-rw-r--r-- | src/client/views/nodes/DataVizBox/DataVizBox.tsx | 25 | ||||
-rw-r--r-- | src/client/views/pdf/GPTPopup/GPTPopup.tsx | 10 |
3 files changed, 37 insertions, 2 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts index c97d29d6f..2de87586b 100644 --- a/src/client/apis/gpt/GPT.ts +++ b/src/client/apis/gpt/GPT.ts @@ -24,7 +24,9 @@ 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." }, + 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 only return a JSON with a correlation column 1 propert, a correlation column 2 property, and an analysis property. " }, + }; /** diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx index 60c5fdba2..24199a5e3 100644 --- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx +++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx @@ -29,6 +29,7 @@ import { PieChart } from './components/PieChart'; import { TableBox } from './components/TableBox'; import { Checkbox } from '@mui/material'; import { ContextMenu } from '../../ContextMenu'; +import { DragManager } from '../../../util/DragManager'; export enum DataVizView { TABLE = 'table', @@ -417,6 +418,7 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() im askGPT = action(async () => { GPTPopup.Instance.setSidebarId('data_sidebar'); GPTPopup.Instance.addDoc = this.sidebarAddDocument; + GPTPopup.Instance.createFilteredDoc = this.createFilteredDoc; GPTPopup.Instance.setDataJson(""); GPTPopup.Instance.setMode(GPTPopupMode.DATA); let data = DataVizBox.dataset.get(CsvCast(this.dataDoc[this.fieldKey]).url.href); @@ -425,6 +427,29 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() im GPTPopup.Instance.generateDataAnalysis(); }); + createFilteredDoc = (axes?: any, type?: DataVizView) => { + + const embedding = Doc.MakeEmbedding(this.Document!); + embedding._dataViz = DataVizView.HISTOGRAM; + embedding._dataViz_axes = new List<string>(axes); + embedding._dataViz_parentViz = this.Document; + embedding.histogramBarColors = Field.Copy(this.layoutDoc.histogramBarColors); + embedding.defaultHistogramColor = this.layoutDoc.defaultHistogramColor; + embedding.pieSliceColors = Field.Copy(this.layoutDoc.pieSliceColors); + this._props.addDocument?.(embedding); + embedding._dataViz_axes = new List<string>([this.axes[1]]) + this.layoutDoc.dataViz_selectedRows = new List<number>(this.records.map((rec, i) => i)) + + console.log(embedding.x); + console.log(Number(embedding.x)); + console.log(Number(embedding.x) + 100.0) + embedding.x = Number(embedding.x) + 100.0; + console.log(embedding.x); + // embedding.y = StrCast(Number(embedding.y) + 100); + + return true; + }; + render() { const scale = this._props.NativeDimScaling?.() || 1; return !this.records.length ? ( diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx index 29b1ca365..50835a541 100644 --- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx +++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx @@ -15,6 +15,7 @@ import { DocUtils, Docs } from '../../../documents/Documents'; import { ObservableReactComponent } from '../../ObservableReactComponent'; import { AnchorMenu } from '../AnchorMenu'; import './GPTPopup.scss'; +import { DataVizView } from '../../nodes/DataVizBox/DataVizBox'; export enum GPTPopupMode { SUMMARY, @@ -121,6 +122,7 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> { }; public addDoc: (doc: Doc | Doc[], sidebarKey?: string | undefined) => boolean = () => false; + public createFilteredDoc: (axes?: any, type?: DataVizView) => boolean = () => false; public addToCollection: ((doc: Doc | Doc[], annotationKey?: string | undefined) => boolean) | undefined; /** @@ -168,7 +170,11 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> { GPTPopup.Instance.setLoading(true); try { let res = await gptAPICall(this.dataJson, GPTCallType.DATA, this.dataChatPrompt); - GPTPopup.Instance.setText(res || 'Something went wrong.'); + console.log(res) + let json = JSON.parse(res! as string); + const keys = Object.keys(json) + console.log(json[keys[0]], json[keys[1]]) + GPTPopup.Instance.setText(json[keys[2]] || 'Something went wrong.'); } catch (err) { console.error(err); } @@ -192,6 +198,8 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> { link_relationship: 'GPT Summary', }); } + + this.createFilteredDoc(); }; /** |