feat: refactoring llms to subfolder

old-agentic-v1^2
Travis Fischer 2023-06-07 12:09:00 -07:00
rodzic bc1d53ba48
commit 66c96591ab
13 zmienionych plików z 36 dodań i 25 usunięć

Wyświetl plik

@ -1,11 +1,10 @@
import * as types from './types'
import { defaultOpenAIModel } from './constants'
// import { BaseTask } from './task'
import {
HumanFeedbackMechanism,
HumanFeedbackMechanismCLI
} from './human-feedback'
import { OpenAIChatModel } from './openai'
import { OpenAIChatModel } from './llms/openai'
export class Agentic {
// _taskMap: WeakMap<string, BaseTask<any, any>>

Wyświetl plik

@ -1,8 +1,6 @@
export * from './agentic'
export * from './task'
export * from './llm'
export * from './openai'
export * from './anthropic'
export * from './llms'
export * from './tokenizer'
export * from './human-feedback'

Wyświetl plik

@ -2,8 +2,9 @@ import * as anthropic from '@anthropic-ai/sdk'
import { type SetOptional } from 'type-fest'
import { ZodTypeAny, z } from 'zod'
import * as types from './types'
import { defaultAnthropicModel } from './constants'
import * as types from '@/types'
import { defaultAnthropicModel } from '@/constants'
import { BaseChatModel } from './llm'
const defaultStopSequences = [anthropic.HUMAN_PROMPT]

Wyświetl plik

@ -0,0 +1,3 @@
export * from './llm'
export * from './openai'
export * from './anthropic'

Wyświetl plik

@ -5,18 +5,18 @@ import { type SetRequired } from 'type-fest'
import { ZodRawShape, ZodTypeAny, z } from 'zod'
import { printNode, zodToTs } from 'zod-to-ts'
import * as types from './types'
import { BaseTask } from './task'
import { getCompiledTemplate } from './template'
import * as types from '@/types'
import { BaseTask } from '@/task'
import { getCompiledTemplate } from '@/template'
import {
Tokenizer,
getModelNameForTiktoken,
getTokenizerForModel
} from './tokenizer'
} from '@/tokenizer'
import {
extractJSONArrayFromString,
extractJSONObjectFromString
} from './utils'
} from '@/utils'
export abstract class BaseLLM<
TInput extends ZodRawShape | ZodTypeAny = z.ZodVoid,
@ -317,6 +317,8 @@ export abstract class BaseChatModel<
tokensPerName = 1
} else {
// TODO
tokensPerMessage = 4
tokensPerName = -1
}
const numTokensPerMessage = await pMap(
@ -342,6 +344,7 @@ export abstract class BaseChatModel<
}
)
// TODO
numTokensTotal += 3 // every reply is primed with <|start|>assistant<|message|>
return { numTokensTotal, numTokensPerMessage }

Wyświetl plik

@ -1,8 +1,9 @@
import { type SetOptional } from 'type-fest'
import { ZodTypeAny, z } from 'zod'
import * as types from './types'
import { defaultOpenAIModel } from './constants'
import * as types from '@/types'
import { defaultOpenAIModel } from '@/constants'
import { BaseChatModel } from './llm'
export class OpenAIChatModel<

Wyświetl plik

@ -68,8 +68,8 @@ export async function getTokenizerForEncoding(
encoding: TiktokenEncoding,
options?: {
signal?: AbortSignal
extendedSpecialTokens?: Record<string, number>
timeoutMs?: number
extendedSpecialTokens?: Record<string, number>
}
) {
const tiktokenBPE = await getTiktokenBPE(encoding, options)
@ -81,8 +81,8 @@ export async function getTokenizerForModel(
model: string,
options?: {
signal?: AbortSignal
extendedSpecialTokens?: Record<string, number>
timeoutMs?: number
extendedSpecialTokens?: Record<string, number>
}
) {
const modelName = getModelNameForTiktoken(model)

Wyświetl plik

@ -1,9 +1,9 @@
import { z } from 'zod'
import * as types from '../types'
import { Agentic } from '../agentic'
import { MetaphorClient } from '../services/metaphor'
import { BaseTask } from '../task'
import * as types from '@/types'
import { Agentic } from '@/agentic'
import { MetaphorClient } from '@/services/metaphor'
import { BaseTask } from '@/task'
export const MetaphorSearchToolInputSchema = z.object({
query: z.string(),

Wyświetl plik

@ -7,7 +7,7 @@ import Keyv from 'keyv'
import { OpenAIClient } from 'openai-fetch'
import pMemoize from 'p-memoize'
import { Agentic } from '../src'
import { Agentic } from '@/agentic'
export const fakeOpenAIAPIKey = 'fake-openai-api-key'
export const fakeAnthropicAPIKey = 'fake-anthropic-api-key'

Wyświetl plik

@ -1,7 +1,8 @@
import test from 'ava'
import { expectTypeOf } from 'expect-type'
import { AnthropicChatModel } from '../src'
import { AnthropicChatModel } from '@/llms/anthropic'
import { createTestAgenticRuntime } from './_utils'
test('AnthropicChatModel ⇒ string output', async (t) => {

Wyświetl plik

@ -2,7 +2,8 @@ import test from 'ava'
import { expectTypeOf } from 'expect-type'
import { z } from 'zod'
import { OpenAIChatModel } from '../src'
import { OpenAIChatModel } from '@/llms/openai'
import { createTestAgenticRuntime } from './_utils'
test('OpenAIChatModel ⇒ string output', async (t) => {

Wyświetl plik

@ -1,6 +1,7 @@
import test from 'ava'
import { SerpAPIClient } from '../src/services/serpapi'
import { SerpAPIClient } from '@/services/serpapi'
import './_utils'
test('SerpAPIClient.search', async (t) => {

Wyświetl plik

@ -15,7 +15,10 @@
"jsx": "preserve",
"baseUrl": ".",
"outDir": "build",
"noEmit": true
"noEmit": true,
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", "build"],
"include": ["**/*.ts", "**/*.tsx"]