Skip to content

Commit

Permalink
update prompt and removed unused codes
Browse files Browse the repository at this point in the history
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
  • Loading branch information
ruanyl committed May 28, 2024
1 parent 66857df commit 0c6fe4f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 42 deletions.
3 changes: 3 additions & 0 deletions src/plugins/vis_type_vega/public/text_to_vega.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ${ppl}
The user's instruction is: ${input}
when a field has a dot(.), you should escape the dot if the field is a single field. For example, if the field is "user.name", but the data is {"user.name": "John"}, the field should be escaped. But it should not be escaped if the data is {"user": {"name": "John"}}
If mark.type = point and shape.field is a field of the data, the definition of the shape should be inside the root "encoding" object, NOT in the "mark" object, for example, {"encoding": {"shape": {"field": "field_name"}}}
Just return the chart specification json based on Vega-Lite format.
Just reply with the json based Vega-Lite object, do not include any other content in the reply.
`;
Expand Down
42 changes: 0 additions & 42 deletions src/plugins/vis_type_vega/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,46 +44,6 @@ import {
} from './vega_visualization_client_wrapper';
import { setDataSourceEnabled } from './services';

const invokeText2Vega = async (
prompt: string,
modelId = 'anthropic.claude-3-sonnet-20240229-v1:0'
// modelId = 'anthropic.claude-3-haiku-20240307-v1:0'
) => {
// Create a new Bedrock Runtime client instance.
const client = new BedrockRuntimeClient({
region: 'us-east-1',
credentials: {
accessKeyId: process.env.ACCESS_KEY_ID ?? '',
secretAccessKey: process.env.SECRET_ACCESS_KEY ?? '',
},
});

// Prepare the payload for the model.
const payload = {
anthropic_version: 'bedrock-2023-05-31',
max_tokens: 4000,
temperature: 0.0,
messages: [
{
role: 'user',
content: [{ type: 'text', text: prompt }],
},
],
};

// Invoke Claude with the payload and wait for the response.
const command = new InvokeModelCommand({
contentType: 'application/json',
body: JSON.stringify(payload),
modelId,
});
const apiResponse = await client.send(command);

const decodedResponseBody = new TextDecoder().decode(apiResponse.body);
const responseBody = JSON.parse(decodedResponseBody);
return responseBody.content[0].text as string;
};

export class VisTypeVegaPlugin implements Plugin<VisTypeVegaPluginSetup, VisTypeVegaPluginStart> {
private readonly config: ConfigObservable;

Expand Down Expand Up @@ -117,8 +77,6 @@ export class VisTypeVegaPlugin implements Plugin<VisTypeVegaPluginSetup, VisType
},
},
router.handleLegacyErrors(async (context, req, res) => {
// const result = await invokeText2Vega(req.body.query);
// return res.ok({ body: result });
const result = await context.core.opensearch.client.asCurrentUser.transport.request({
method: 'POST',
path: '/_plugins/_ml/models/_yV0hY8B8ef_5QXJp6Xd/_predict',
Expand Down

0 comments on commit 0c6fe4f

Please sign in to comment.