@shenghuabi/openai 1.1.46 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/chat/chat.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Context, StreamOptions } from '@earendil-works/pi-ai';
2
+ import { ModelConfigInputType } from './util/get-custom-provider';
3
+ import type OpenAI from 'openai';
4
+ import { Injector } from 'static-injector';
5
+ export declare function createChatStream(input: ModelConfigInputType): (context: Context, options?: StreamOptions, extra?: {
6
+ response_format?: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming["response_format"];
7
+ injector?: Injector;
8
+ }) => AsyncGenerator<import("@earendil-works/pi-ai").AssistantMessageEvent, void, unknown>;
package/chat/module.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { ChatHistoryService } from './chat.history.service';
2
- import { ChatProviderService } from './service';
3
1
  export declare const OPENAI_MODULE: {
4
- provider: (typeof ChatHistoryService | typeof ChatProviderService)[];
2
+ provider: never[];
5
3
  token: {
6
4
  OpenAIConfigToken: import("static-injector").InjectionToken<import("static-injector").Signal<import("./type").OpenAIConfig>>;
7
5
  };
@@ -0,0 +1,3 @@
1
+ import * as v from 'valibot';
2
+ export declare const KnownProviderDefine: v.SchemaWithPipe<readonly [v.PicklistSchema<["amazon-bedrock", "anthropic", "google", "google-vertex", "openai", "azure-openai-responses", "openai-codex", "deepseek", "github-copilot", "xai", "groq", "cerebras", "openrouter", "vercel-ai-gateway", "zai", "mistral", "minimax", "minimax-cn", "moonshotai", "moonshotai-cn", "huggingface", "fireworks", "together", "opencode", "opencode-go", "kimi-coding", "cloudflare-workers-ai", "cloudflare-ai-gateway", "xiaomi", "xiaomi-token-plan-cn", "xiaomi-token-plan-ams", "xiaomi-token-plan-sgp", "ant-ling", "nvidia", "zai-coding-cn", "openai-completions", "openai-responses", "anthropic-messages"], undefined>, v.TitleAction<"deepseek" | "amazon-bedrock" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "together" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp" | "ant-ling" | "nvidia" | "zai-coding-cn" | "openai-completions" | "openai-responses" | "anthropic-messages", "提供商">, v.DescriptionAction<"deepseek" | "amazon-bedrock" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "together" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp" | "ant-ling" | "nvidia" | "zai-coding-cn" | "openai-completions" | "openai-responses" | "anthropic-messages", "'openai-completions','openai-responses','anthropic-messages',为自定义提供商">]>;
3
+ export type KnownProviderType = v.InferOutput<typeof KnownProviderDefine>;
package/chat/type.d.ts CHANGED
@@ -1,14 +1,4 @@
1
1
  import { ChatMessageListOutputType } from './message.define';
2
- export interface ResolvedChatOptions {
3
- model: string;
4
- temperature: number;
5
- topP: number;
6
- maxTokens: number;
7
- baseURL: string;
8
- verbose: boolean;
9
- apiKey: string;
10
- vendor: string;
11
- }
12
2
  interface ResponseFormatText {
13
3
  type: 'text';
14
4
  }
@@ -42,19 +32,8 @@ export type RunnableToolFunctionWithParse = {
42
32
  export type ChatToolBodyInput = ChatBodyInput & {
43
33
  tools: RunnableToolFunctionWithParse[];
44
34
  };
45
- export interface ChatRequestOptions {
46
- headers?: Record<string, string | null | undefined>;
47
- signal?: AbortSignal | undefined;
48
- tryPull?: (error: any) => boolean;
49
- pullModel?: (name: string) => Promise<any>;
50
- }
51
35
  export interface OpenAIConfig {
52
36
  tryPull?: () => boolean;
53
37
  pullModel?: (name: string) => Promise<any>;
54
- captureException: (error: any) => any;
55
- history: {
56
- dir: string;
57
- enable: boolean;
58
- };
59
38
  }
60
39
  export {};
@@ -0,0 +1,30 @@
1
+ import { Context, StreamOptions, FauxResponseStep } from '@earendil-works/pi-ai';
2
+ /**
3
+ * 创建一个基于用户输入动态返回响应的方法。
4
+ * @param responseFactory - 根据上下文动态生成响应的工厂函数,接收历史消息和调用序号,返回文本或文本数组
5
+ */
6
+ export declare function createDynamicResponse(responseFactory: (context: Context, callCount: number) => string | string[]): (context: Context, _options: StreamOptions | undefined, state: {
7
+ callCount: number;
8
+ }) => Promise<import("@earendil-works/pi-ai").AssistantMessage>;
9
+ /** Options for registerFauxProvider. */
10
+ export interface MockProviderOptions {
11
+ api?: string;
12
+ provider?: string;
13
+ tokensPerSecond?: number;
14
+ }
15
+ /**
16
+ * Register a faux mock provider and return a ready-to-use model with cleanup.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const { model, setResponses, unregister } = registerMockProvider();
21
+ * setResponses([fauxAssistantMessage('hello')]);
22
+ * const response = await complete(model, { messages: [{ role: 'user', content: 'hi', timestamp: Date.now() }] });
23
+ * unregister(); // clean up when done
24
+ * ```
25
+ */
26
+ export declare function registerMockProvider(options?: MockProviderOptions): {
27
+ model: import("@earendil-works/pi-ai").Model<string>;
28
+ setResponses: (responses: FauxResponseStep[]) => void;
29
+ unregister: () => void;
30
+ };