fix(llm.gblib): Tool fix. More templates.
This commit is contained in:
parent
95458a658d
commit
6aaae55a61
10 changed files with 66 additions and 14 deletions
|
@ -71,7 +71,7 @@ import {
|
|||
SQL_MYSQL_PROMPT
|
||||
} from 'langchain/chains/sql_db';
|
||||
import { GBUtil } from '../../../src/util.js';
|
||||
|
||||
import { z } from 'zod';
|
||||
export interface CustomOutputParserFields {}
|
||||
export type ExpectedOutput = any;
|
||||
|
||||
|
@ -475,7 +475,7 @@ export class ChatServices {
|
|||
|
||||
result = res.text ? res.text : res;
|
||||
sources = res.sources;
|
||||
} else if (LLMMode === 'function') {
|
||||
} else if (LLMMode === 'tool') {
|
||||
result = await conversationalToolChain.invoke({
|
||||
question
|
||||
});
|
||||
|
@ -639,7 +639,8 @@ export class ChatServices {
|
|||
|
||||
if (funcObj) {
|
||||
// TODO: Use ajv.
|
||||
funcObj.schema = eval(jsonSchemaToZod(funcObj.parameters));
|
||||
|
||||
funcObj.schema = jsonSchemaToZod(funcObj.parameters);
|
||||
functions.push(new DynamicStructuredTool(funcObj));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,4 +79,32 @@ export class ImageServices {
|
|||
return { localName, url };
|
||||
}
|
||||
}
|
||||
|
||||
public async getCaptionForImage({ pid, imageUrl }) {
|
||||
const { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||
|
||||
const azureOpenAIKey = await min.core.getParam(min.instance, 'Azure Open AI Key', null);
|
||||
const azureOpenAITextModel = 'gpt-4'; // Specify GPT-4 model here
|
||||
const azureOpenAIEndpoint = await min.core.getParam(min.instance, 'Azure Open AI Endpoint', null);
|
||||
|
||||
if (azureOpenAIKey && azureOpenAITextModel && imageUrl) {
|
||||
// Initialize the Azure OpenAI client
|
||||
const client = new OpenAI({ apiKey: azureOpenAIKey, baseURL: azureOpenAIEndpoint });
|
||||
|
||||
// Construct a prompt to describe the image and generate a caption
|
||||
const prompt = `Provide a descriptive caption for the image at the following URL: ${imageUrl}`;
|
||||
|
||||
// Generate a caption using GPT-4
|
||||
const response = await client.completions.create({
|
||||
model: azureOpenAITextModel,
|
||||
prompt: prompt,
|
||||
max_tokens: 50
|
||||
});
|
||||
|
||||
const caption = response['data'].choices[0].text.trim();
|
||||
GBLogEx.info(min, `Generated caption: ${caption}`);
|
||||
|
||||
return { caption };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
7
templates/llm-tools.gbai/llm-tools.gbdata/products.csv
Normal file
7
templates/llm-tools.gbai/llm-tools.gbdata/products.csv
Normal file
|
@ -0,0 +1,7 @@
|
|||
name,price
|
||||
Product A, 230
|
||||
Product B, 120
|
||||
Product C, 180
|
||||
Product D, 250
|
||||
Product E, 200
|
||||
Product F, 150
|
|
|
@ -1,5 +1,4 @@
|
|||
PARAM image
|
||||
PARAM image AS STRING LIKE "https://server/image"
|
||||
DESCRIPTION Returns the description of the image that was sent with the previous user message. This tool is automatically invoked if a user uploads an image.
|
||||
|
||||
|
||||
|
||||
DEBUG "Hello"
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
PARAM prompt
|
||||
PARAM prompt as STRING LIKE "Generate a cat."
|
||||
DESCRIPTION Calls an artificial intelligence model to create an image. `prompt` parameter is a text description of the desired image.
|
||||
|
||||
|
||||
|
||||
FIND
|
||||
RETURN "https://"
|
|
@ -0,0 +1,6 @@
|
|||
PARAM product AS string LIKE "Product A"
|
||||
DESCRIPTION "Returns the price of the given product."
|
||||
|
||||
product = FIND "products.csv", "name LIKE ${product}"
|
||||
price = product.price
|
||||
RETURN price
|
|
@ -1,2 +1,4 @@
|
|||
PARAM query
|
||||
PARAM query AS STRING LIKE "How is to code?"
|
||||
DESCRIPTION Returns search results in a JSON string. `query` parameter is a well-formed web search query.- `search_web(query: str) -> str` returns Bing search results in a JSON string. `query` parameter is a well-formed web search query.
|
||||
|
||||
DEBUG "{}"
|
9
templates/llm-tools.gbai/llm-tools.gbdialog/start.bas
Normal file
9
templates/llm-tools.gbai/llm-tools.gbdialog/start.bas
Normal file
|
@ -0,0 +1,9 @@
|
|||
BEGIN SYSTEM PROMPT
|
||||
|
||||
There exist some helpful predefined internal tools which can help me by
|
||||
extending my functionalities or get me helpful information.
|
||||
These tools **should** be abstracted away from the user.
|
||||
These tools can be invoked only by me before I respond to a user.
|
||||
Here is the list of my internal tools:
|
||||
|
||||
END SYSTEM PROMPT
|
2
templates/llm-tools.gbai/llm-tools.gbot/config.csv
Normal file
2
templates/llm-tools.gbai/llm-tools.gbot/config.csv
Normal file
|
@ -0,0 +1,2 @@
|
|||
name,value
|
||||
Answer Mode,tool
|
|
|
@ -5,7 +5,7 @@ pass = "*************"
|
|||
o = get "https://oooooooooo"
|
||||
|
||||
# Criar a legenda para o post
|
||||
caption = REWRITE "Crie um post sobre Hotmart e seus produtos, no estilo dica do dia, incluindo 10 hashtags, estilo Instagram o texto! Importante, retorne só a saída de texto pronta"
|
||||
caption = REWRITE "Crie um post sobre produtos, no estilo dica do dia, incluindo 10 hashtags, estilo Instagram o texto! Importante, retorne só a saída de texto pronta"
|
||||
|
||||
# Obter uma imagem relacionada ao conteúdo
|
||||
image = GET IMAGE caption
|
||||
|
|
Loading…
Add table
Reference in a new issue