You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* add job zod schema
* refactor: update job parameter types to use specific schemas for chat, embedding, and image jobs
* feat: implement models() function for OpenAI, Ollama, and Anthropic providers
* docs: update README to reflect changes in models listing and add usage example
* refactor: make options field optional in baseJobSchema
* schema based on provider
* simplify chat stream
* fix utils
* add job result schema
* add google provider
* update README to include instructions for requesting support for new AI providers
* add groq example
* add job.remote()
* update schemas and fix dump type
* fmt
* fix test
* fix type
* rename job types
* add schema file
* refactor: reorganize chat job types and introduce ChatTool class
* add builder class
* seems working
* revert example
* fix some imports
* exclude zod in dist
* fix more types
* fix more types
* update types
* fix typo
* add provider
* update job schemas and add TypeScript check in github action
* add deepseek provider
* deepseek models
* fix job type
* zod v4
* fix test, add ChatStream
* fix job schema export
* add jobStream() helper
* rename example
* include response json in http error
* add job output schema
* fix vision chat
* add partial json
* fix readme
---------
Co-authored-by: Bruce Shi <shibocuhk@gmail.com>
> This project is in beta. The API is subject to changes and may break.
@@ -10,21 +10,24 @@ fluent-ai is a lightweight, type-safe AI toolkit that seamlessly integrates mult
10
10
11
11
## Installation
12
12
13
+
[Zod](https://zod.dev/) is a popular type of validation library for TypeScript and JavaScript that allows developers to define and validate data schemas in a concise and type-safe manner. fluent-ai is built upon zod.
14
+
13
15
```sh
14
-
npm install fluent-ai
16
+
npm install fluent-ai zod@next
15
17
```
16
18
17
19
## AI Service provider support
18
20
19
21
fluent-ai includes support for multiple AI providers and modalities.
By default, API keys for providers are read from environment variable (`process.env`) following the format `<PROVIDER>_API_KEY` (e.g., `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`).
30
33
@@ -47,40 +50,47 @@ Each request to AI providers is wrapped in a `Job`. which can also serialized an
47
50
### Method chaining
48
51
49
52
```ts
50
-
import { openai, userPrompt } from"fluent-ai";
53
+
import { openai, user } from"fluent-ai";
51
54
52
55
const job =openai()
53
56
.chat("gpt-4o-mini")
54
-
.messages([userPrompt("Hi")])
57
+
.messages([user("Hi")])
55
58
.temperature(0.5)
56
59
.maxTokens(1024);
57
60
```
58
61
59
62
### Declaration
60
63
61
-
Alternatively, fluent-ai also supports job declaration from json object.
64
+
Alternatively, fluent-ai supports declarative job creation using JSON objects, with full TypeScript autocompletion support.
62
65
63
66
```ts
64
67
import { load } from"fluent-ai";
65
68
66
69
const job =load({
67
70
provider: "openai",
68
-
chat: {
71
+
type: "chat",
72
+
input: {
69
73
model: "gpt-4o-mini",
70
-
params: {
71
-
messages: [{ role: "user", content: "hi" }],
72
-
temperature: 0.5,
73
-
},
74
+
messages: [{ role: "user", content: "hi" }],
75
+
temperature: 0.5,
74
76
},
75
77
});
76
78
```
77
79
80
+
fluent-ai provides built-in TypeScript type definitions and schema validation for jobs:
81
+
82
+
```ts
83
+
import { typeJob } from"fluent-ai"; // TypeScript type
import { openai, system, user, text } from"fluent-ai";
104
114
105
115
const job =openai()
106
116
.chat("gpt-4o-mini")
107
-
.messages([systemPrompt("You are a helpful assistant"), userPrompt("Hi")]);
108
-
109
-
const { text } =awaitjob.run();
110
-
```
111
-
112
-
### Structured output
113
-
114
-
Structured output from AI chat completions involves formatting the responses based on predefined json schema. This feature is essential when building applications with chat completions.
117
+
.messages([system("You are a helpful assistant"), user("Hi")]);
115
118
116
-
[Zod](https://zod.dev/) is a popular type of validation library for TypeScript and JavaScript that allows developers to define and validate data schemas in a concise and type-safe manner. fluent-ai provides built-in integration for declare json-schema with zod. To use zod integration, first install `zod` from npm. Any parameter in fluent-ai that accepts a JSON schema will also work with a Zod schema.
117
-
118
-
```sh
119
-
npm install zod
120
-
```
121
-
122
-
fluent-ai provides a consistent `jsonSchema()` function for all providers to generate structured output. For more details, refer to the [structured output docs](/docs/chat-structured-outputs.md)
123
-
124
-
```ts
125
-
import { z } from"zod";
126
-
import { openai, userPrompt } from"fluent-ai";
127
-
128
-
const personSchema =z.object({
129
-
name: z.string(),
130
-
age: z.number(),
131
-
});
132
-
133
-
const job =openai()
134
-
.chat("gpt-4o-mini")
135
-
.messages([userPrompt("generate a person with name and age in json format")])
136
-
.jsonSchema(personSchema, "person");
137
-
138
-
const { object } =awaitjob.run();
119
+
const result =awaitjob.run();
120
+
console.log(text(result));
139
121
```
140
122
141
123
### Function calling (tool calling)
@@ -163,9 +145,7 @@ To use the tool, add it to a chat job with a function-calling-enabled model, suc
Feel free to [open an issue](https://github.com/modalityml/fluent-ai/issues) or [start a discussion](https://github.com/modalityml/fluent-ai/discussions) if you have any questions. [Join our Discord community](https://discord.gg/HzGZWbY8Fx)
198
+
Feel free to [open an issue](https://github.com/modalityml/fluent-ai/issues) or [start a discussion](https://github.com/modalityml/fluent-ai/discussions) if you have any questions. If you would like to request support for a new AI provider, please create an issue with details about the provider's API. [Join our Discord community](https://discord.gg/HzGZWbY8Fx) for help and updates.
0 commit comments