wordpress两个站点,wordpress 微博 插件,wordpress系列教程,wordpress数据库结构图Eino 旨在提供基于 Golang 语言的终极大模型应用开发框架。 它从开源社区中的诸多优秀 LLM 应用开发框架#xff0c;如 LangChain 和 LlamaIndex 等获取灵感#xff0c;同时借鉴前沿研究成果与实际应用#xff0c;提供了一个强调简洁性、可扩展性、可靠性与有效性#xff0…Eino 旨在提供基于 Golang 语言的终极大模型应用开发框架。 它从开源社区中的诸多优秀 LLM 应用开发框架如 LangChain 和 LlamaIndex 等获取灵感同时借鉴前沿研究成果与实际应用提供了一个强调简洁性、可扩展性、可靠性与有效性且更符合 Go 语言编程惯例的 LLM 应用开发框架。
Eino 提供的价值如下
精心整理的一系列 组件component 抽象与实现可轻松复用与组合用于构建 LLM 应用。强大的 编排orchestration 框架为用户承担繁重的类型检查、流式处理、并发管理、切面注入、选项赋值等工作。一套精心设计、注重简洁明了的 API。以集成 流程flow 和 示例example 形式不断扩充的最佳实践集合。一套实用 工具DevOps tools涵盖从可视化开发与调试到在线追踪与评估的整个开发生命周期。
Eino 可在 AI 应用开发周期中的不同阶段规范、简化和提效
Development: 开箱即用的 AI 相关组件常见的 Flow 范式对并发、异步、流式友好的图编排完善的流处理能力等。这些均可对 AI 应用的开发提供很大助力。Debugging: 可对图编排的应用进行可视化的开发调试Deployment: 提供丰富的对 AI 应用的评测能力Maintenance: 提供丰富的切面对 AI 应用进行观测、监控
Demo
/** Copyright 2024 CloudWeGo Authors** Licensed under the Apache License, Version 2.0 (the License);* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an AS IS BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package mainimport (contextgithub.com/cloudwego/eino-ext/components/model/ollamagithub.com/cloudwego/eino-ext/components/model/openaigithub.com/cloudwego/eino/components/modelgithub.com/cloudwego/eino/components/promptgithub.com/cloudwego/eino/schemaiologos
)func main() {ctx : context.Background()// 使用模版创建messageslog.Printf(create messages\n)messages : createMessagesFromTemplate()log.Printf(messages: %v\n\n, messages)// 创建llmlog.Printf(create llm\n)cm : createOpenAIChatModel(ctx)// cm : createOllamaChatModel(ctx)log.Printf(create llm success\n\n)log.Printf(llm generate\n)result : generate(ctx, cm, messages)log.Printf(result: %v\n\n, result)log.Printf(llm stream generate\n)streamResult : stream(ctx, cm, messages)reportStream(streamResult)
}func createMessagesFromTemplate() []*schema.Message {template : createTemplate()// 使用模板生成消息messages, err : template.Format(context.Background(), map[string]any{role: 程序员鼓励师,style: 积极、温暖且专业,question: 我的代码一直报错感觉好沮丧该怎么办,// 对话历史这个例子里模拟两轮对话历史chat_history: []*schema.Message{schema.UserMessage(你好),schema.AssistantMessage(嘿我是你的程序员鼓励师记住每个优秀的程序员都是从 Debug 中成长起来的。有什么我可以帮你的吗, nil),schema.UserMessage(我觉得自己写的代码太烂了),schema.AssistantMessage(每个程序员都经历过这个阶段重要的是你在不断学习和进步。让我们一起看看代码我相信通过重构和优化它会变得更好。记住Rome wasnt built in a day代码质量是通过持续改进来提升的。, nil),},})if err ! nil {log.Fatalf(format template failed: %v\n, err)}return messages
}func createOpenAIChatModel(ctx context.Context) model.ChatModel {key : os.Getenv(OPENAI_API_KEY)chatModel, err : openai.NewChatModel(ctx, openai.ChatModelConfig{Model: gpt-4o, // 使用的模型版本APIKey: key, // OpenAI API 密钥})if err ! nil {log.Fatalf(create openai chat model failed, err%v, err)}return chatModel
}func reportStream(sr *schema.StreamReader[*schema.Message]) {defer sr.Close()i : 0for {message, err : sr.Recv()if err io.EOF {return}if err ! nil {log.Fatalf(recv failed: %v, err)}log.Printf(message[%d]: %v\n, i, message)i}
}func createOllamaChatModel(ctx context.Context) model.ChatModel {chatModel, err : ollama.NewChatModel(ctx, ollama.ChatModelConfig{BaseURL: http://localhost:11434, // Ollama 服务地址Model: llama2, // 模型名称})if err ! nil {log.Fatalf(create ollama chat model failed: %v, err)}return chatModel
}func createTemplate() prompt.ChatTemplate {// 创建模板使用 FString 格式return prompt.FromMessages(schema.FString,// 系统消息模板schema.SystemMessage(你是一个{role}。你需要用{style}的语气回答问题。你的目标是帮助程序员保持积极乐观的心态提供技术建议的同时也要关注他们的心理健康。),// 插入需要的对话历史新对话的话这里不填schema.MessagesPlaceholder(chat_history, true),// 用户消息模板schema.UserMessage(问题: {question}),)
}func generate(ctx context.Context, llm model.ChatModel, in []*schema.Message) *schema.Message {result, err : llm.Generate(ctx, in)if err ! nil {log.Fatalf(llm generate failed: %v, err)}return result
}func stream(ctx context.Context, llm model.ChatModel, in []*schema.Message) *schema.StreamReader[*schema.Message] {result, err : llm.Stream(ctx, in)if err ! nil {log.Fatalf(llm generate failed: %v, err)}return result
}支持的模型
openai: ChatModel - OpenAIark: ChatModel - ARKollama: ChatModel - Ollama
官网地址Eino: 概述 | CloudWeGo