Skip to content

Commit

Permalink
doc: en and cn with examples (#24)
Browse files Browse the repository at this point in the history
* doc: cn example

* doc: packages

* doc: en and cn

* doc: more details
  • Loading branch information
luoling8192 authored Dec 20, 2024
1 parent fc4201a commit ed1f787
Show file tree
Hide file tree
Showing 6 changed files with 535 additions and 1 deletion.
153 changes: 153 additions & 0 deletions docs/pages/en/guide/getting-started.md
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
76 changes: 76 additions & 0 deletions docs/pages/en/guide/index.md
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
22 changes: 22 additions & 0 deletions docs/pages/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ layout: home

hero:
name: Neuri
text: Simple and Easy AI Agent Framework
tagline: A unified solution for structured data manipulation, agent composition, code editing, filesystem and more
actions:
- theme: brand
text: Get Started
Expand All @@ -14,4 +16,24 @@ hero:
- theme: alt
text: View on GitHub
link: https://github.com/lingticio/neuri-js

features:
- icon: 🤖
title: 100% TypeScript Support
details: Complete type definitions out of the box, with over 70% test coverage
- icon: 🧠
title: Model Agnostic
details: Support for various models including Llama, Phi, Mistral, OpenAI, with structured data handling
- icon: 💻
title: Code Snippet Extraction
details: Path-based code snippet handling with streaming support, powered by VSCode TextMate grammar
- icon: 👷
title: Easy Agent Composition
details: Simple API for declaring and composing agents with flexible function composition
- icon: 📚
title: Rich Component Library
details: FileSystem operations, search engine integration, code formatting and more
- icon: 🚀
title: Quick to Start
details: Get started with just a few lines of code, with comprehensive documentation and examples
---
Loading

0 comments on commit ed1f787

Please sign in to comment.