-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d31312
commit b640f2e
Showing
21 changed files
with
4,487 additions
and
2,004 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
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
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [llm-ops](./llm-ops.md) > [genMermaid](./llm-ops.genmermaid.md) | ||
|
||
## genMermaid variable | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
genMermaid: (params: MermaidCallSchema) => Promise<string> | ||
``` |
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [llm-ops](./llm-ops.md) > [MermaidCallSchema](./llm-ops.mermaidcallschema.md) > [llm](./llm-ops.mermaidcallschema.llm.md) | ||
|
||
## MermaidCallSchema.llm property | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
llm?: LLM; | ||
``` |
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [llm-ops](./llm-ops.md) > [MermaidCallSchema](./llm-ops.mermaidcallschema.md) > [llmSchema](./llm-ops.mermaidcallschema.llmschema.md) | ||
|
||
## MermaidCallSchema.llmSchema property | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
llmSchema?: createLLMSchema; | ||
``` |
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,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [llm-ops](./llm-ops.md) > [MermaidCallSchema](./llm-ops.mermaidcallschema.md) | ||
|
||
## MermaidCallSchema interface | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
export interface MermaidCallSchema | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Modifiers | Type | Description | | ||
| --- | --- | --- | --- | | ||
| [llm?](./llm-ops.mermaidcallschema.llm.md) | | [LLM](./llm-ops.llm.md) | _(Optional)_ | | ||
| [llmSchema?](./llm-ops.mermaidcallschema.llmschema.md) | | [createLLMSchema](./llm-ops.createllmschema.md) | _(Optional)_ | | ||
| [request](./llm-ops.mermaidcallschema.request.md) | | [messageType](./llm-ops.messagetype.md) \| string | | | ||
| [type?](./llm-ops.mermaidcallschema.type.md) | | string \| string\[\] | _(Optional)_ | | ||
|
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [llm-ops](./llm-ops.md) > [MermaidCallSchema](./llm-ops.mermaidcallschema.md) > [request](./llm-ops.mermaidcallschema.request.md) | ||
|
||
## MermaidCallSchema.request property | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
request: messageType | string; | ||
``` |
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [llm-ops](./llm-ops.md) > [MermaidCallSchema](./llm-ops.mermaidcallschema.md) > [type](./llm-ops.mermaidcallschema.type.md) | ||
|
||
## MermaidCallSchema.type property | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
type?: string | string[]; | ||
``` |
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 |
---|---|---|
@@ -1,75 +1,78 @@ | ||
# 部署 | ||
|
||
`llm-ops`作为一款支持`commonjs`、`esm`、`ts`的框架,可以在任何支持`nodejs`的环境中运行,包括`linux`、`macos`、`windows`等。 | ||
|
||
> 由于部分使用的依赖问题,暂不支持直接在浏览器中部署,之后会改进。 | ||
## next/nuxt | ||
|
||
虽然`llm-ops`暂时无法直接在浏览器中使用,但是一般也不可能直接在浏览器中使用,防止`api-key`泄露。 | ||
|
||
在前端,可以使用`next`或者`nuxt`来进行`SSR/CSR`渲染,核心功能防止服务端,前端调用对应函数即可。 | ||
|
||
这里以next框架为例,介绍如何在前端使用`llm-ops`。 | ||
|
||
完整项目代码可见[Github](https://github.com/MarleneJiang/llm-ops-preview) | ||
|
||
```js | ||
|
||
'use server' | ||
import { Pipeline, PipeRegistry, LLM_OPS_CONFIG,EventEmitter } from "llm-ops"; | ||
import { useAppContext } from "@/lib/AppContext"; | ||
export const llm_ops_run = async ( | ||
schema, | ||
inputText, | ||
openaiKey, | ||
heliconeKey | ||
) => { | ||
try { | ||
|
||
LLM_OPS_CONFIG.OPENAI_API_KEY = openaiKey || ""; | ||
!!heliconeKey && (LLM_OPS_CONFIG.HELICONE_AUTH_API_KEY = heliconeKey); | ||
!!heliconeKey && (LLM_OPS_CONFIG.OPEN_PATH = { | ||
baseURL: "https://oai.hconeai.com/v1", | ||
defaultHeaders: { | ||
"Helicone-Auth": `Bearer ${heliconeKey}`, | ||
}, | ||
}); | ||
const funcStore = PipeRegistry.init(); | ||
const schemaJson = JSON.parse(schema); | ||
const pipeline = Pipeline.fromJSON(schemaJson, {}, funcStore); | ||
const res = await pipeline.execute(inputText); | ||
return res; | ||
} catch (e) { | ||
throw e | ||
} | ||
}; | ||
``` | ||
|
||
## laf | ||
|
||
`llm-ops`可以直接部署在`serveless`云函数中,这里以`laf`为例,介绍如何在`laf`中使用`llm-ops`。 | ||
|
||
```ts | ||
import cloud from '@lafjs/cloud' | ||
import { Pipeline, PipeRegistry, SerializablePipelineOptions } from "llm-ops"; | ||
export default async function (ctx: FunctionContext) { | ||
const { schema, input } = ctx.body; | ||
if (!schema || !input) { | ||
return { "code": "001", "msg": "错误输入", "data": "" }; | ||
} | ||
console.log("schema", schema) | ||
const funcStore = PipeRegistry.init(); | ||
if (!!schema.pipes) { | ||
const pipeline = Pipeline.fromJSON(schema as SerializablePipelineOptions, {}, funcStore); | ||
const res = await pipeline.execute(input); | ||
return { "code": "200", "msg": "", "data": res }; | ||
} else { | ||
return { "code": "002", "msg": "schema.pipes错误输入", "data": "" }; | ||
} | ||
} | ||
``` | ||
|
||
借助`laf`的能力,我们能够迅速将其部署到云函数中,实现`llm-ops`的在线调用。 | ||
|
||
完整的laf函数代码可见[函数市场](https://laf.run/market/templates/6517c102d2f60c23eb96807d) | ||
# 部署 | ||
|
||
`llm-ops`作为一款支持`commonjs`、`esm`、`ts`的框架,可以在任何支持`nodejs`的环境中运行,包括`linux`、`macos`、`windows`等。 | ||
|
||
> 由于部分使用的依赖问题,暂不支持直接在浏览器中部署,之后会改进。 | ||
## next/nuxt | ||
|
||
虽然`llm-ops`暂时无法直接在浏览器中使用,但是一般也不可能直接在浏览器中使用,防止`api-key`泄露。 | ||
|
||
在前端,可以使用`next`或者`nuxt`来进行`SSR/CSR`渲染,核心功能防止服务端,前端调用对应函数即可。 | ||
|
||
这里以next框架为例,介绍如何在前端使用`llm-ops`。 | ||
|
||
完整项目代码可见[Github](https://github.com/MarleneJiang/llm-ops-preview) | ||
|
||
```js | ||
"use server"; | ||
import { Pipeline, PipeRegistry, LLM_OPS_CONFIG, EventEmitter } from "llm-ops"; | ||
import { useAppContext } from "@/lib/AppContext"; | ||
export const llm_ops_run = async ( | ||
schema, | ||
inputText, | ||
openaiKey, | ||
heliconeKey, | ||
) => { | ||
try { | ||
LLM_OPS_CONFIG.OPENAI_API_KEY = openaiKey || ""; | ||
!!heliconeKey && (LLM_OPS_CONFIG.HELICONE_AUTH_API_KEY = heliconeKey); | ||
!!heliconeKey && | ||
(LLM_OPS_CONFIG.OPEN_PATH = { | ||
baseURL: "https://oai.hconeai.com/v1", | ||
defaultHeaders: { | ||
"Helicone-Auth": `Bearer ${heliconeKey}`, | ||
}, | ||
}); | ||
const funcStore = PipeRegistry.init(); | ||
const schemaJson = JSON.parse(schema); | ||
const pipeline = Pipeline.fromJSON(schemaJson, {}, funcStore); | ||
const res = await pipeline.execute(inputText); | ||
return res; | ||
} catch (e) { | ||
throw e; | ||
} | ||
}; | ||
``` | ||
|
||
## laf | ||
|
||
`llm-ops`可以直接部署在`serveless`云函数中,这里以`laf`为例,介绍如何在`laf`中使用`llm-ops`。 | ||
|
||
```ts | ||
import cloud from "@lafjs/cloud"; | ||
import { Pipeline, PipeRegistry, SerializablePipelineOptions } from "llm-ops"; | ||
export default async function (ctx: FunctionContext) { | ||
const { schema, input } = ctx.body; | ||
if (!schema || !input) { | ||
return { code: "001", msg: "错误输入", data: "" }; | ||
} | ||
console.log("schema", schema); | ||
const funcStore = PipeRegistry.init(); | ||
if (!!schema.pipes) { | ||
const pipeline = Pipeline.fromJSON( | ||
schema as SerializablePipelineOptions, | ||
{}, | ||
funcStore, | ||
); | ||
const res = await pipeline.execute(input); | ||
return { code: "200", msg: "", data: res }; | ||
} else { | ||
return { code: "002", msg: "schema.pipes错误输入", data: "" }; | ||
} | ||
} | ||
``` | ||
|
||
借助`laf`的能力,我们能够迅速将其部署到云函数中,实现`llm-ops`的在线调用。 | ||
|
||
完整的laf函数代码可见[函数市场](https://laf.run/market/templates/6517c102d2f60c23eb96807d) |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./llm.js"; | ||
export * from "./llm.js"; |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { genMermaid } from "llm-ops"; | ||
|
||
test("genMermaid", async () => { | ||
const res = await genMermaid({ | ||
request:"在对数字化转型的探讨中,技术、策略和人是三大核心要素。技术为数字化转型提供了可能性,允许企业利用先进的工具和平台去优化、创新和扩展其业务范围。而策略则为数字化转型提供了方向,确保企业的技术部署与其长期的商业目标和愿景相一致。最后,人是数字化转型的中心,因为不论有多先进的技术或策略,如果员工和客户不能或不愿适应新的变革,那么转型就不可能成功。因此,在进行数字化转型时,企业必须确保技术的适用性、策略的明晰性和人的参与性,以确保转型的全面性和成功性。" | ||
}); | ||
genMermaid({ | ||
request: | ||
"在对数字化转型的探讨中,技术、策略和人是三大核心要素。技术为数字化转型提供了可能性,允许企业利用先进的工具和平台去优化、创新和扩展其业务范围。而策略则为数字化转型提供了方向,确保企业的技术部署与其长期的商业目标和愿景相一致。最后,人是数字化转型的中心,因为不论有多先进的技术或策略,如果员工和客户不能或不愿适应新的变革,那么转型就不可能成功。因此,在进行数字化转型时,企业必须确保技术的适用性、策略的明晰性和人的参与性,以确保转型的全面性和成功性。", | ||
}).then((res) => { | ||
console.log(res); | ||
}); | ||
}); |
Oops, something went wrong.