-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(constants): move core/constants to constants package (#726)
We otherwise have circular dependencies between core and other packages that make it hard to develop and test.
- Loading branch information
Showing
21 changed files
with
380 additions
and
336 deletions.
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
8 changes: 4 additions & 4 deletions
8
...pi/v2/projects/[projectId]/versions/[versionUuid]/documents/handlers/documentPresenter.ts
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
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
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 |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import { | ||
CoreTool, | ||
LanguageModelUsage, | ||
ObjectStreamPart, | ||
TextStreamPart, | ||
} from 'ai' | ||
import { JSONSchema7 } from 'json-schema' | ||
import { ToolCall, Message } from '@latitude-data/compiler' | ||
import { z } from 'zod' | ||
|
||
import { ProviderLog } from './models' | ||
|
||
type GoogleConfig = z.infer<typeof googleConfig> | ||
|
||
const googleCategorySettings = z.union([ | ||
z.literal('HARM_CATEGORY_HATE_SPEECH'), | ||
z.literal('HARM_CATEGORY_DANGEROUS_CONTENT'), | ||
z.literal('HARM_CATEGORY_HARASSMENT'), | ||
z.literal('HARM_CATEGORY_SEXUALLY_EXPLICIT'), | ||
]) | ||
const googleThresholdSettings = z.union([ | ||
z.literal('HARM_BLOCK_THRESHOLD_UNSPECIFIED'), | ||
z.literal('BLOCK_LOW_AND_ABOVE'), | ||
z.literal('BLOCK_MEDIUM_AND_ABOVE'), | ||
z.literal('BLOCK_ONLY_HIGH'), | ||
z.literal('BLOCK_NONE'), | ||
]) | ||
|
||
export const googleConfig = z | ||
.object({ | ||
structuredOutputs: z.boolean().optional(), | ||
cachedContent: z.string().optional(), | ||
safetySettings: z | ||
.array( | ||
z | ||
.object({ | ||
category: googleCategorySettings.optional(), | ||
threshold: googleThresholdSettings.optional(), | ||
}) | ||
.optional(), | ||
) | ||
.optional(), | ||
}) | ||
.optional() | ||
|
||
export type PartialConfig = Omit<Config, 'provider'> | ||
|
||
export type Config = { | ||
provider: string | ||
model: string | ||
url?: string | ||
cacheControl?: boolean | ||
schema?: JSONSchema7 | ||
azure?: { resourceName: string } | ||
google?: GoogleConfig | ||
tools?: Record< | ||
string, | ||
{ description?: string; parameters: Record<string, any> } | ||
> | ||
} | ||
|
||
export enum ChainEventTypes { | ||
Error = 'chain-error', | ||
Step = 'chain-step', | ||
Complete = 'chain-complete', | ||
StepComplete = 'chain-step-complete', | ||
} | ||
|
||
export type ProviderData = | ||
| TextStreamPart<Record<string, CoreTool>> | ||
| ObjectStreamPart<Record<string, CoreTool>> | ||
| ObjectStreamPart<unknown> | ||
|
||
export type ChainEventDto = | ||
| ProviderData | ||
| { | ||
type: ChainEventTypes.Step | ||
config: Config | ||
isLastStep: boolean | ||
messages: Message[] | ||
uuid?: string | ||
} | ||
| { | ||
type: ChainEventTypes.StepComplete | ||
response: ChainEventDtoResponse | ||
uuid?: string | ||
} | ||
| { | ||
type: ChainEventTypes.Complete | ||
config: Config | ||
messages?: Message[] | ||
object?: any | ||
response: ChainEventDtoResponse | ||
uuid?: string | ||
} | ||
| { | ||
type: ChainEventTypes.Error | ||
error: { | ||
name: string | ||
message: string | ||
stack?: string | ||
} | ||
} | ||
|
||
export type ChainCallResponseDto = | ||
| Omit<ChainStepResponse<'object'>, 'documentLogUuid' | 'providerLog'> | ||
| Omit<ChainStepResponse<'text'>, 'documentLogUuid' | 'providerLog'> | ||
|
||
type ChainEventDtoResponse = | ||
| Omit<ChainStepResponse<'object'>, 'providerLog'> | ||
| Omit<ChainStepResponse<'text'>, 'providerLog'> | ||
|
||
export type StreamType = 'object' | 'text' | ||
type BaseResponse = { | ||
text: string | ||
usage: LanguageModelUsage | ||
documentLogUuid?: string | ||
providerLog?: ProviderLog | ||
} | ||
|
||
export type ChainStepTextResponse = BaseResponse & { | ||
streamType: 'text' | ||
toolCalls: ToolCall[] | ||
} | ||
|
||
export type ChainStepObjectResponse = BaseResponse & { | ||
streamType: 'object' | ||
object: any | ||
} | ||
|
||
export type ChainStepResponse<T extends StreamType> = T extends 'text' | ||
? ChainStepTextResponse | ||
: T extends 'object' | ||
? ChainStepObjectResponse | ||
: never | ||
|
||
export enum StreamEventTypes { | ||
Latitude = 'latitude-event', | ||
Provider = 'provider-event', | ||
} | ||
|
||
export type ChainEvent = | ||
| { | ||
data: LatitudeEventData | ||
event: StreamEventTypes.Latitude | ||
} | ||
| { | ||
data: ProviderData | ||
event: StreamEventTypes.Provider | ||
} | ||
|
||
export type LatitudeEventData = | ||
| { | ||
type: ChainEventTypes.Step | ||
config: Config | ||
isLastStep: boolean | ||
messages: Message[] | ||
documentLogUuid?: string | ||
} | ||
| { | ||
type: ChainEventTypes.StepComplete | ||
response: ChainStepResponse<StreamType> | ||
documentLogUuid?: string | ||
} | ||
| { | ||
type: ChainEventTypes.Complete | ||
config: Config | ||
messages?: Message[] | ||
object?: any | ||
response: ChainStepResponse<StreamType> | ||
documentLogUuid?: string | ||
} | ||
| { | ||
type: ChainEventTypes.Error | ||
error: Error | ||
} | ||
|
||
// FIXME: Move to @latitude-data/constants | ||
export type RunSyncAPIResponse = { | ||
uuid: string | ||
conversation: Message[] | ||
response: ChainCallResponseDto | ||
} | ||
|
||
// FIXME: Move to @latitude-data/constants | ||
export type ChatSyncAPIResponse = RunSyncAPIResponse |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export enum LogSources { | ||
API = 'api', | ||
Playground = 'playground', | ||
Evaluation = 'evaluation', | ||
User = 'user', | ||
SharedPrompt = 'shared_prompt', | ||
} | ||
|
||
export enum Providers { | ||
OpenAI = 'openai', | ||
Anthropic = 'anthropic', | ||
Groq = 'groq', | ||
Mistral = 'mistral', | ||
Azure = 'azure', | ||
Google = 'google', | ||
Custom = 'custom', | ||
} | ||
|
||
export * from './models' | ||
export * from './ai' |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { LogSources } from '.' | ||
import { Message, ToolCall } from '@latitude-data/compiler' | ||
import { PartialConfig } from './ai' | ||
|
||
export type DocumentLog = { | ||
id: number | ||
uuid: string | ||
documentUuid: string | ||
commitId: number | ||
resolvedContent: string | ||
contentHash: string | ||
parameters: Record<string, unknown> | ||
customIdentifier: string | null | ||
duration: number | null | ||
source: LogSources | null | ||
createdAt: Date | ||
updatedAt: Date | ||
} | ||
|
||
export enum EvaluationResultableType { | ||
Boolean = 'evaluation_resultable_booleans', | ||
Text = 'evaluation_resultable_texts', | ||
Number = 'evaluation_resultable_numbers', | ||
} | ||
|
||
export type EvaluationResult = { | ||
id: number | ||
uuid: string | ||
evaluationId: number | ||
documentLogId: number | ||
evaluatedProviderLogId: number | null | ||
evaluationProviderLogId: number | null | ||
resultableType: EvaluationResultableType | null | ||
resultableId: number | null | ||
source: LogSources | null | ||
reason: string | null | ||
createdAt: Date | ||
updatedAt: Date | ||
} | ||
|
||
export type EvaluationResultDto = EvaluationResult & { | ||
result: string | number | boolean | undefined | ||
} | ||
|
||
export type ProviderLog = { | ||
id: number | ||
uuid: string | ||
documentLogUuid: string | null | ||
providerId: number | null | ||
model: string | null | ||
finishReason: string | null | ||
config: PartialConfig | null | ||
messages: Message[] | ||
responseObject: unknown | null | ||
responseText: string | null | ||
toolCalls: ToolCall[] | ||
tokens: number | null | ||
costInMillicents: number | null | ||
duration: number | null | ||
source: LogSources | null | ||
apiKeyId: number | null | ||
generatedAt: Date | null | ||
updatedAt: Date | ||
} | ||
|
||
export type DocumentVersion = { | ||
id: number | ||
documentUuid: string | ||
path: string | ||
content: string | ||
resolvedContent: string | ||
contentHash: string | ||
promptlVersion: number | ||
commitId: number | ||
datasetId: number | null | ||
deletedAt: Date | null | ||
createdAt: Date | ||
updatedAt: Date | ||
} |
Oops, something went wrong.