Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UXE-0000] - Fix/ai agent #221

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions templates/typescript/azion-react-agent/setup/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export default async function azionVectorStoreSetup() {
const vectorStore = new AzionVectorStore(embeddingModel, {dbName:process.env.VECTOR_STORE_DB_NAME, tableName:process.env.VECTOR_STORE_TABLE_NAME})

// Add documents to the vector store
// await vectorStore.addDocuments(productDocs)
await vectorStore.addDocuments(productDocs)

// Use the vector store as retriever
const docs = await vectorStore.AzionHybridSearch("what is good for headache?",{kfts:1,kvector:1})
console.log(JSON.stringify(docs, null, 2))
// const docs = await vectorStore.AzionHybridSearch("what is good for headache?",{kfts:1,kvector:1})
// console.log(JSON.stringify(docs, null, 2))
}

azionVectorStoreSetup()
11 changes: 11 additions & 0 deletions templates/typescript/azion-react-agent/src/helper/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,24 @@ export class AzionEdgeTracer {
}
}

/**
* Remove the single quotes from input, output and run metadata
*/
removeSingleQuotesFromStrings(): void {
this.inputMessages = this.inputMessages.map((message:string) => message.replace(/'/g, ""))
this.outputMessages = this.outputMessages.replace(/'/g, "")
this.runMetadata = this.runMetadata?.map((message:string) => message.replace(/'/g, ""))
}

/**
* Save the trace into the database
*/
async save() {
console.log("Saving trace into ", this.databaseName, "for session ", this.sessionId)
const createdAt = new Date().toISOString()
this.removeSingleQuotesFromStrings()
const statements = [`INSERT INTO ${this.tableName} (session_id, run_id, input_messages, output_messages, run_metadata, created_at) VALUES ('${this.sessionId}', '${this.runId}', '${this.inputMessages}', '${this.outputMessages}', '${this.runMetadata}', '${createdAt}')`]

const { data, error } = await useExecute(this.databaseName,statements)
if (error) {
console.error("Error saving trace:", error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,24 @@ export class AzionRetriever extends BaseRetriever {
entityExtractionPrompt,
new HumanMessage(query),
]);
return entityQuery.content.toString().replace(/[^a-zA-Z0-9\s]/g, ' ').split(' ').join(' OR ')

return this.convert2FTSQuery(entityQuery.content.toString())
}

/**
* Converts a query to a FTS query.
* @param query The user query
* @returns The converted FTS query
*/
protected convert2FTSQuery(
query: string
): string {
return query
.replace(/[^a-záàâãéèêíïóôõöúçñA-ZÁÀÂÃÉÈÊÍÏÓÔÕÖÚÇÑ0-9\s]/g, '') // Remove special chars keeping accents
.replace(/\s+/g, ' ') // Remove multiple spaces
.trim() // Remove leading/trailing spaces
.split(' ')
.join(' OR ');
}

/**
Expand Down