kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
Merge branch 'main' of https://github.com/transitive-bullshit/agentic
commit
ca6dd03cd3
|
@ -13,12 +13,12 @@ export async function main() {
|
||||||
)
|
)
|
||||||
.input(z.object({ texts: z.string().array() }))
|
.input(z.object({ texts: z.string().array() }))
|
||||||
.output(z.array(z.object({ text: z.string(), label: z.string() })))
|
.output(z.array(z.object({ text: z.string(), label: z.string() })))
|
||||||
.examples([
|
// .examples([
|
||||||
{ input: 'The food was digusting', output: 'negative' },
|
// { input: 'The food was digusting', output: 'negative' },
|
||||||
{ input: 'We had a fantastic night', output: 'positive' },
|
// { input: 'We had a fantastic night', output: 'positive' },
|
||||||
{ input: 'Recommended', output: 'positive' },
|
// { input: 'Recommended', output: 'positive' },
|
||||||
{ input: 'The waiter was rude', output: 'negative' }
|
// { input: 'The waiter was rude', output: 'negative' }
|
||||||
])
|
// ])
|
||||||
.call({
|
.call({
|
||||||
texts: [
|
texts: [
|
||||||
'I went to this place and it was just so awful.',
|
'I went to this place and it was just so awful.',
|
||||||
|
|
22
readme.md
22
readme.md
|
@ -15,6 +15,7 @@
|
||||||
- [Development](#development)
|
- [Development](#development)
|
||||||
- [Environment](#environment)
|
- [Environment](#environment)
|
||||||
- [Local Testing](#local-testing)
|
- [Local Testing](#local-testing)
|
||||||
|
- [Scratch](#scratch)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
|
|
||||||
## Intro
|
## Intro
|
||||||
|
@ -55,6 +56,27 @@ Ensure you have `REDIS_URL_TEST` set to a valid redis connection URL.
|
||||||
pnpm test
|
pnpm test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Scratch
|
||||||
|
|
||||||
|
- `@agentic/core`
|
||||||
|
- Task, Agentic, logging, caching, types, constants
|
||||||
|
- `@agentic/human-feedback`
|
||||||
|
- `@agentic/human-feedback-cli`
|
||||||
|
- `@agentic/human-feedback-sms`
|
||||||
|
- `@agentic/human-feedback-slack`
|
||||||
|
- `@agentic/experimenation`
|
||||||
|
- `@agentic/tools`
|
||||||
|
- `@agentic/tools-serpapi`
|
||||||
|
- `@agentic/tools-metaphor`
|
||||||
|
- `@agentic/tools-browser`
|
||||||
|
- `@agentic/tools-multion`
|
||||||
|
- `@agentic/llms`
|
||||||
|
- `@agentic/llms-openai`
|
||||||
|
- `@agentic/llms-anthropic`
|
||||||
|
- `@agentic/llms-huggingface`
|
||||||
|
- `@agentic/agents`
|
||||||
|
- `@agentic/cli`
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT © [Travis Fischer](https://transitivebullsh.it)
|
MIT © [Travis Fischer](https://transitivebullsh.it)
|
||||||
|
|
|
@ -30,6 +30,9 @@ async function ExampleLLMQuery({ texts }: { texts: string[] }) {
|
||||||
>
|
>
|
||||||
<System>You are an expert sentiment-labelling assistant</System>
|
<System>You are an expert sentiment-labelling assistant</System>
|
||||||
|
|
||||||
|
{/* <ConversationHistory /> */}
|
||||||
|
{/* <PineconeMemory /> */}
|
||||||
|
|
||||||
<User>
|
<User>
|
||||||
Label the following texts as positive or negative:
|
Label the following texts as positive or negative:
|
||||||
{/* {texts.map((text) => `- ${text}\n`)} */}
|
{/* {texts.map((text) => `- ${text}\n`)} */}
|
||||||
|
|
20
src/llm.ts
20
src/llm.ts
|
@ -86,12 +86,6 @@ export abstract class BaseLLM<
|
||||||
this._modelParams = { ...this._modelParams, ...params } as TModelParams
|
this._modelParams = { ...this._modelParams, ...params } as TModelParams
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
// abstract stream({
|
|
||||||
// input: TInput,
|
|
||||||
// onProgress: types.ProgressFunction
|
|
||||||
// }): Promise<TOutput>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class BaseChatModel<
|
export abstract class BaseChatModel<
|
||||||
|
@ -117,9 +111,9 @@ export abstract class BaseChatModel<
|
||||||
messages: types.ChatMessage[]
|
messages: types.ChatMessage[]
|
||||||
): Promise<types.BaseChatCompletionResponse<TChatCompletionResponse>>
|
): Promise<types.BaseChatCompletionResponse<TChatCompletionResponse>>
|
||||||
|
|
||||||
override async call(
|
protected override async _call(
|
||||||
input?: types.ParsedData<TInput>
|
input?: types.ParsedData<TInput>
|
||||||
): Promise<types.ParsedData<TOutput>> {
|
): Promise<types.TaskResponse<TOutput>> {
|
||||||
if (this._inputSchema) {
|
if (this._inputSchema) {
|
||||||
const inputSchema =
|
const inputSchema =
|
||||||
this._inputSchema instanceof z.ZodType
|
this._inputSchema instanceof z.ZodType
|
||||||
|
@ -248,9 +242,15 @@ export abstract class BaseChatModel<
|
||||||
|
|
||||||
// TODO: handle errors, retry logic, and self-healing
|
// TODO: handle errors, retry logic, and self-healing
|
||||||
|
|
||||||
return outputSchema.parse(output)
|
return {
|
||||||
|
result: outputSchema.parse(output),
|
||||||
|
metadata: {}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return output
|
return {
|
||||||
|
result: output,
|
||||||
|
metadata: {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
src/task.ts
25
src/task.ts
|
@ -6,8 +6,12 @@ import { Agentic } from './agentic'
|
||||||
/**
|
/**
|
||||||
* A `Task` is a typed, async function call that may be non-deterministic.
|
* A `Task` is a typed, async function call that may be non-deterministic.
|
||||||
*
|
*
|
||||||
|
* Invoking a task is equivalent to sampling from a probability distribution.
|
||||||
|
*
|
||||||
* Examples of tasks include:
|
* Examples of tasks include:
|
||||||
* - LLM calls
|
* - LLM calls
|
||||||
|
* - Chain of LLM calls
|
||||||
|
* - Retrieval task
|
||||||
* - API calls
|
* - API calls
|
||||||
* - Native function calls
|
* - Native function calls
|
||||||
* - Invoking sub-agents
|
* - Invoking sub-agents
|
||||||
|
@ -17,8 +21,9 @@ export abstract class BaseTask<
|
||||||
TOutput extends ZodRawShape | ZodTypeAny = ZodTypeAny
|
TOutput extends ZodRawShape | ZodTypeAny = ZodTypeAny
|
||||||
> {
|
> {
|
||||||
protected _agentic: Agentic
|
protected _agentic: Agentic
|
||||||
protected _timeoutMs: number | undefined
|
|
||||||
protected _retryConfig: types.RetryConfig | undefined
|
protected _timeoutMs?: number
|
||||||
|
protected _retryConfig?: types.RetryConfig
|
||||||
|
|
||||||
constructor(options: types.BaseTaskOptions) {
|
constructor(options: types.BaseTaskOptions) {
|
||||||
this._agentic = options.agentic
|
this._agentic = options.agentic
|
||||||
|
@ -45,9 +50,21 @@ export abstract class BaseTask<
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract call(
|
public async call(
|
||||||
input?: types.ParsedData<TInput>
|
input?: types.ParsedData<TInput>
|
||||||
): Promise<types.ParsedData<TOutput>>
|
): Promise<types.ParsedData<TOutput>> {
|
||||||
|
return this._call(input).then((response) => response.result)
|
||||||
|
}
|
||||||
|
|
||||||
|
public async callWithMetadata(
|
||||||
|
input?: types.ParsedData<TInput>
|
||||||
|
): Promise<types.TaskResponse<TOutput>> {
|
||||||
|
return this._call(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract _call(
|
||||||
|
input?: types.ParsedData<TInput>
|
||||||
|
): Promise<types.TaskResponse<TOutput>>
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// abstract stream({
|
// abstract stream({
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
import * as types from '../types'
|
||||||
import { Agentic } from '../agentic'
|
import { Agentic } from '../agentic'
|
||||||
import { MetaphorClient } from '../services/metaphor'
|
import { MetaphorClient } from '../services/metaphor'
|
||||||
import { BaseTask } from '../task'
|
import { BaseTask } from '../task'
|
||||||
|
@ -57,15 +58,20 @@ export class MetaphorSearchTool extends BaseTask<
|
||||||
return MetaphorSearchToolOutputSchema
|
return MetaphorSearchToolOutputSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
override async call(
|
protected override async _call(
|
||||||
input: MetaphorSearchToolInput
|
input: MetaphorSearchToolInput
|
||||||
): Promise<MetaphorSearchToolOutput> {
|
): Promise<types.TaskResponse<typeof MetaphorSearchToolOutputSchema>> {
|
||||||
// TODO: handle errors gracefully
|
// TODO: handle errors gracefully
|
||||||
input = this.inputSchema.parse(input)
|
input = this.inputSchema.parse(input)
|
||||||
|
|
||||||
return this._metaphorClient.search({
|
const result = await this._metaphorClient.search({
|
||||||
query: input.query,
|
query: input.query,
|
||||||
numResults: input.numResults
|
numResults: input.numResults
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
result,
|
||||||
|
metadata: {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,4 +105,12 @@ export interface RetryConfig {
|
||||||
strategy: string
|
strategy: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TaskResponse<
|
||||||
|
TOutput extends ZodRawShape | ZodTypeAny = z.ZodType<string>,
|
||||||
|
TMetadata extends Record<string, any> = Record<string, any>
|
||||||
|
> {
|
||||||
|
result: ParsedData<TOutput>
|
||||||
|
metadata: TMetadata
|
||||||
|
}
|
||||||
|
|
||||||
// export type ProgressFunction = (partialResponse: ChatMessage) => void
|
// export type ProgressFunction = (partialResponse: ChatMessage) => void
|
||||||
|
|
Ładowanie…
Reference in New Issue