Closed joshuacox closed 1 week ago
@joshuacox we will upgrade llamaindex to fix this soon
I deleted all initializers aside from Ollama in settings.ts after taking this lines advice:
// HINT: you can delete the initialization code for unused model providers
Which I did to no effect. It still complains about the missing API key. I tried setting a false key to get it to ignore the issue, but of course openAI rejects the API call. But I do not want it contacting openAI at all.
EDIT: of course I submitted that comment and then the refresh happened and I see the comment from you @marcusschiesser
hi @joshuacox
Can you please initialize with npx create-llama@latest --pro
rather than npx create-llama@latest
, and update .env? This works for me.
should be fixed in Release 0.3.10 - please have a try
hi @marcusschiesser
Unfortunately, updating LlamaIndex to version 0.8.2 didn't resolve the issue. If it would be helpful, I can share the differences between the files when initialized with --pro versus without it.
without-pro/app/api/chat/engine:
import {
BaseChatEngine,
BaseToolWithCall,
OpenAIAgent,
QueryEngineTool,
} from "llamaindex";
import fs from "node:fs/promises";
import path from "node:path";
import { getDataSource } from "./index";
import { generateFilters } from "./queryFilter";
import { createTools } from "./tools";
export async function createChatEngine(documentIds?: string[], params?: any) {
const tools: BaseToolWithCall[] = [];
// Add a query engine tool if we have a data source
// Delete this code if you don't have a data source
const index = await getDataSource(params);
if (index) {
tools.push(
new QueryEngineTool({
queryEngine: index.asQueryEngine({
preFilters: generateFilters(documentIds || []),
}),
metadata: {
name: "data_query_engine",
description: `A query engine for documents from your data source.`,
},
}),
);
}
const configFile = path.join("config", "tools.json");
let toolConfig: any;
try {
// add tools from config file if it exists
toolConfig = JSON.parse(await fs.readFile(configFile, "utf8"));
} catch (e) {
console.info(`Could not read ${configFile} file. Using no tools.`);
}
if (toolConfig) {
tools.push(...(await createTools(toolConfig)));
}
const agent = new OpenAIAgent({
tools,
systemPrompt: process.env.SYSTEM_PROMPT,
}) as unknown as BaseChatEngine;
return agent;
}
with-pro//app/api/chat/engine:
import { ContextChatEngine, Settings } from "llamaindex";
import { getDataSource } from "./index";
import { nodeCitationProcessor } from "./nodePostprocessors";
import { generateFilters } from "./queryFilter";
export async function createChatEngine(documentIds?: string[], params?: any) {
const index = await getDataSource(params);
if (!index) {
throw new Error(
`StorageContext is empty - call 'npm run generate' to generate the storage first`,
);
}
const retriever = index.asRetriever({
similarityTopK: process.env.TOP_K ? parseInt(process.env.TOP_K) : undefined,
filters: generateFilters(documentIds || []),
});
const systemPrompt = process.env.SYSTEM_PROMPT;
const citationPrompt = process.env.SYSTEM_CITATION_PROMPT;
const prompt =
[systemPrompt, citationPrompt].filter((p) => p).join("\n") || undefined;
const nodePostprocessors = citationPrompt
? [nodeCitationProcessor]
: undefined;
return new ContextChatEngine({
chatModel: Settings.llm,
retriever,
systemPrompt: prompt,
nodePostprocessors,
});
}
const agent = new OpenAIAgent
I guess we need to fix this part.
@mcavdar great catch, it should be actually generate to use the LLMAgent
instead of the OpenAIAgent
- I fixed this in https://github.com/run-llama/create-llama/pull/410
Unfortunately, the Ollama LLM class from LlamaIndexTS doesn't support tool calls yet, I added this in https://github.com/run-llama/LlamaIndexTS/issues/1430
Once, this is added to LITS, it will automatically work in create-llama (after update). I keep this ticket open for tracking
sorry for the delay, but this is working great for me now, closing. Feel free to re-open if there are some other issues.
just for others, you need to update LllamaIndexTS if it doesn't work
How do I prevent openAI from being invoked at all?
.env
<question 1> <question 2> <question 3>