mirror of
https://github.com/run-llama/tool.git
synced 2026-07-01 21:14:06 -04:00
docs: update README.md
This commit is contained in:
@@ -9,7 +9,49 @@
|
||||
|
||||
## Usage
|
||||
|
||||
### Node.js
|
||||
### In your code
|
||||
|
||||
```ts
|
||||
// @file: index.llama.ts
|
||||
export function getWeather(city: string) {
|
||||
return `The weather in ${city} is sunny.`
|
||||
}
|
||||
export function getTemperature(city: string) {
|
||||
return `The temperature in ${city} is 25°C.`
|
||||
}
|
||||
export function getCurrentCity() {
|
||||
return 'New York'
|
||||
}
|
||||
// @file: app.ts
|
||||
import Tools from './index.llama'
|
||||
import { registerTools, convertTools } from '@llamaindex/tool'
|
||||
// Register tools on top level
|
||||
registerTools(Tools)
|
||||
|
||||
import { OpenAI } from 'openai'
|
||||
const openai = new OpenAI()
|
||||
openai.chat.completions.create({
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is the weather in the current city?'
|
||||
}
|
||||
],
|
||||
tools: convertTools('openai')
|
||||
})
|
||||
|
||||
// or you can use llamaindex openai agent
|
||||
import { OpenAIAgent } from 'llamaindex'
|
||||
const agent = new OpenAIAgent({
|
||||
tools: convertTools('llamaindex')
|
||||
})
|
||||
const { response } = await agent.chat({
|
||||
message: 'What is the temperature in the current city?'
|
||||
})
|
||||
console.log('Response:', response)
|
||||
```
|
||||
|
||||
### Run with Node.js
|
||||
|
||||
```shell
|
||||
node --import tsx --import @llamaindex/tool/register ./app.ts
|
||||
|
||||
Reference in New Issue
Block a user