-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* doc: cn example * doc: packages * doc: en and cn * doc: more details
- Loading branch information
1 parent
fc4201a
commit ed1f787
Showing
6 changed files
with
535 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,154 @@ | ||
# Getting Started | ||
|
||
## Installation | ||
|
||
Install Neuri using your favorite package manager: | ||
|
||
```bash | ||
pnpm add neuri | ||
``` | ||
|
||
## Basic Usage | ||
|
||
```ts | ||
import { env } from 'node:process' | ||
import { | ||
composeAgent, | ||
defineToolFunction, | ||
resolveFirstTextContentFromChatCmpl, | ||
system, | ||
toolFunction, | ||
user, | ||
} from 'neuri/openai' | ||
import OpenAI from 'openai' | ||
import * as z from 'zod' | ||
|
||
// Create OpenAI client instance | ||
const openai: OpenAI = new OpenAI({ | ||
baseURL: env.OPENAI_API_BASEURL, | ||
apiKey: env.OPENAI_API_KEY, | ||
}) | ||
|
||
// Compose Agent and tool functions | ||
const { call } = composeAgent({ | ||
openAI: openai, | ||
tools: [ | ||
// Define a tool function to get city | ||
defineToolFunction<Record<string, never>, string>( | ||
await toolFunction('getCity', 'Get the user\'s city', z.object({})), | ||
async () => { | ||
return 'New York City' | ||
} | ||
), | ||
// Define a tool function to get weather | ||
defineToolFunction<{ cityCode: string }, { city: string, weather: string, degreesCelsius: number }>( | ||
await toolFunction('getWeather', 'Get the current weather', z.object({ | ||
cityCode: z.string().min(1).describe('City code to get weather for') | ||
})), | ||
async ({ parameters: { cityCode } }) => { | ||
return { | ||
city: 'New York City', | ||
weather: 'sunny', | ||
degreesCelsius: 26 | ||
} | ||
} | ||
) | ||
] | ||
}) | ||
|
||
// Call Agent for conversation | ||
const response = await call([ | ||
system('I am a helpful assistant that can provide weather information.'), | ||
user('What is the weather like today?') | ||
], { | ||
model: 'openai/gpt-3.5-turbo' | ||
}) | ||
|
||
const result = resolveFirstTextContentFromChatCmpl(response) | ||
console.log(result) | ||
``` | ||
|
||
## Extension Packages | ||
|
||
### @neuri/use-fs | ||
|
||
Filesystem related tool functions package, supporting local filesystem and GitHub repository operations. | ||
|
||
```ts | ||
import { FileSystem } from '@neuri/use-fs/node' | ||
import { GitHubPublicFileSystem } from '@neuri/use-fs/github' | ||
|
||
// Local filesystem | ||
const fs = await FileSystem() | ||
const { readFile, writeFile, listFilesInDirectory } = fs | ||
|
||
// GitHub repository operations | ||
const github = await GitHubPublicFileSystem() | ||
const { listFilesInDirectory: listGitHubFiles, readFile: readGitHubFile } = github | ||
``` | ||
|
||
### @neuri/use-search | ||
|
||
Search engine related tool functions package, currently supporting Google search (via SerpAPI). | ||
|
||
```ts | ||
import { SerpApi } from '@neuri/use-search/serpapi' | ||
|
||
const serpapi = await SerpApi({ | ||
apiKey: 'your-serpapi-key' | ||
}) | ||
|
||
const { searchGoogle } = serpapi | ||
``` | ||
|
||
### @neuri/format-code | ||
|
||
Code formatting and syntax highlighting related tool functions package. | ||
|
||
```ts | ||
import { tokenizeByTextMateGrammar } from '@neuri/format-code/textmate' | ||
|
||
// Use TextMate grammar to parse code | ||
const result = await tokenizeByTextMateGrammar('typescript', code) | ||
``` | ||
|
||
## API Reference | ||
|
||
### Core APIs | ||
|
||
#### neuri() | ||
|
||
Create a new Neuri builder instance. | ||
|
||
#### agent(name?: string) | ||
|
||
Create a new Agent builder instance. | ||
|
||
Parameters: | ||
- `name`: Agent name, optional. Defaults to `__default__` | ||
|
||
#### composeAgent(options) | ||
|
||
Compose Agent and tool functions. | ||
|
||
Parameters: | ||
- `options.openAI`: OpenAI client instance | ||
- `options.tools`: Array of tool functions | ||
|
||
#### defineToolFunction(tool, func, options?) | ||
|
||
Define a tool function. | ||
|
||
Parameters: | ||
- `tool`: Tool function definition created by `toolFunction()` | ||
- `func`: Tool function implementation | ||
- `options`: Optional configuration including provider and hooks | ||
|
||
#### toolFunction(name, description, parameters) | ||
|
||
Create a tool function definition. | ||
|
||
Parameters: | ||
- `name`: Tool function name | ||
- `description`: Tool function description | ||
- `parameters`: Parameter Schema, supports zod or valibot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,77 @@ | ||
# Overview | ||
|
||
Neuri is a simple and easy-to-use AI Agent framework that provides a complete toolkit to help you quickly build OpenAI-based AI applications. | ||
|
||
## Features | ||
|
||
- 📦 **100% TypeScript Support** - Complete type definitions out of the box | ||
- ✅ **High Test Coverage** - Over 70% test coverage ensures reliability | ||
- 🧠 **Model Agnostic** - Structured data support for various models including Llama 3.1, Phi3.5 Mistral, OpenAI, etc. | ||
- 📃 **JSON Structured Data** | ||
- Works with streaming responses | ||
- Clean and type-safe data handling | ||
- 💻 **Code Snippet Extraction** | ||
- Supports streaming extraction | ||
- Path-based code snippet handling | ||
- Powered by VSCode TextMate grammar | ||
- 👷 **Easy Agent Composition** | ||
- Simple API for declaring and composing agents | ||
- Flexible function composition | ||
- Built-in tool function system | ||
- 📚 **Rich Component Library** | ||
- FileSystem operations (local & GitHub) | ||
- Search engine integration | ||
- Code formatting utilities | ||
|
||
### Simple Agent Framework | ||
|
||
Neuri is built on OpenAI's Function Calling feature and provides a simple agent framework. You just need to define tool functions, and then let AI automatically choose the right tools to complete tasks. | ||
|
||
```ts | ||
const agent = await neuri() | ||
.agent( | ||
agent('weather') | ||
.tool('getCurrentLocation', object({}), async () => 'Shanghai') | ||
.tool('getCurrentWeather', object({ location: string() }), | ||
async ({ parameters: { location } }) => { | ||
return `${location}, China: 22 degree Celsius` | ||
}) | ||
.build() | ||
) | ||
.build({ | ||
provider: { | ||
apiKey: process.env.OPENAI_API_KEY!, | ||
baseURL: process.env.OPENAI_API_BASEURL!, | ||
}, | ||
}) | ||
``` | ||
|
||
### Rich Tool Functions | ||
|
||
Neuri provides multiple extension packages, including: | ||
|
||
- `@neuri/use-fs`: Filesystem operations, supporting local filesystem and GitHub repositories | ||
- `@neuri/use-search`: Search engine integration, supporting Google search | ||
- `@neuri/format-code`: Code formatting and syntax highlighting | ||
|
||
### Type Safe | ||
|
||
Neuri is written in TypeScript and provides complete type definitions. Tool function parameters and return values are type-checked to make your code more robust. | ||
|
||
### Modular Design | ||
|
||
Neuri uses a modular design where core functionality and extension packages are separated. You can import only the features you need to reduce bundle size. | ||
|
||
## Related Projects | ||
|
||
- [neuri-go](https://github.com/lingticio/neuri-go) - Go implementation of Neuri | ||
- [llmg](https://github.com/lingticio/llmg) - Powerful LLM gateway for building LLM applications | ||
- [devtools](https://github.com/guiiai/devtools) - Frontend DevTools with LLM copilot features | ||
- [ollama-operator](https://github.com/nekomeowww/ollama-operator) - Kubernetes operator for Ollama | ||
- [nolebase/integrations](https://github.com/nolebase/integrations) - Documentation integrations powered by VitePress | ||
|
||
## Next Steps | ||
|
||
- [Getting Started](/pages/en/guide/getting-started): Learn how to install and use Neuri | ||
- [GitHub](https://github.com/lingticio/neuri-js): Visit the project repository | ||
- [Discord](https://discord.gg/link-to-your-discord): Join the community discussion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.