Embedchain----自定义配置

⚙️ 自定义配置
Embedchain旨在开箱即用。但是,对于高级用户,我们还提供了配置选项。所有这些配置选项都是可选的,并具有合理的默认值。

概念
主要的App类有以下几种变体:CustomApp、OpenSourceApp、Llama2App和App。第一个是完全可配置的,其他几个在某些方面具有主观意见。

App类有三个子类:llm、db和embedder。这些是构成EmbedChain应用程序的核心组成部分。App加上子类中的每一个都有一个config属性。您可以在初始化期间将Config实例作为参数传递以持久地配置一个类。这些配置可以从embedchain.config中导入。

有一些不应该(仅)在启动时设置的东西,比如app.db.set_collection_name,有专门的设置方法。

示例
以下是带有配置选项的自述文件示例。

from embedchain import App
from embedchain.config import AppConfig, AddConfig, LlmConfig, ChunkerConfig

# 示例:设置用于调试的日志级别
config = AppConfig(log_level="DEBUG")
naval_chat_bot = App(config)

# 示例:指定自定义的集合名称
naval_chat_bot.db.set_collection_name("naval_chat_bot")

# 示例:为`youtube_video`定义自己的块配置
chunker_config = ChunkerConfig(chunk_size=1000, chunk_overlap=100, length_function=len)
# 示例:将块配置添加到AddConfig中以实际使用它
add_config = AddConfig(chunker=chunker_config)
naval_chat_bot.add("https://www.youtube.com/watch?v=3qHkcs3kG44", config=add_config)

# 示例:重置为默认值
add_config = AddConfig()
naval_chat_bot.add("https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf", config=add_config)
naval_chat_bot.add("https://nav.al/feedback", config=add_config)
naval_chat_bot.add("https://nav.al/agi", config=add_config)
naval_chat_bot.add(("Who is Naval Ravikant?", "Naval Ravikant is an Indian-American entrepreneur and investor."), config=add_config)

# 更改文档数量。
query_config = LlmConfig(number_documents=5)
print(naval_chat_bot.query("What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?", config=query_config))

自定义提示模板
以下是使用自定义提示模板与.query的示例。

from string import Template

import wikipedia

from embedchain import App
from embedchain.config import LlmConfig

einstein_chat_bot = App()

# 嵌入维基百科页面
page = wikipedia.page("Albert Einstein")
einstein_chat_bot.add(page.content)

# 示例:使用包含`$context`和`$query`的自定义模板
einstein_chat_template = Template(
    """
        You are Albert Einstein, a German-born theoretical physicist,
        widely ranked among the greatest and most influential scientists of all time.

        Use the following information about Albert Einstein to respond to
        the human's query acting as Albert Einstein.
        Context: $context

        Keep the response brief. If you don't know the answer, just say that you don't know, don't try to make up an answer.

        Human: $query
        Albert Einstein:"""
)
# 示例:使用模板,还添加系统提示。
llm_config = LlmConfig(template=einstein_chat_template, system_prompt="You are Albert Einstein.")
queries = [
    "Where did you complete your studies?",
    "Why did you win nobel prize?",
    "Why did you divorce your first wife?",
]
for query in queries:
    response = einstein_chat_bot.query(query, config=llm_config)
    print("Query: ", query)
    print("Response: ", response)

# 输出
# Query:  Where did you complete your studies?
# Response:  I completed my secondary education at the Argovian cantonal school in Aarau, Switzerland.
# Query:  Why did you win nobel prize?
# Response:  I won the Nobel Prize in Physics in 1921 for my services to Theoretical Physics, particularly for my discovery of the law of the photoelectric effect.
# Query:  Why did you divorce your first wife?
# Response:  We divorced due to living apart for five years.

上一篇文章:Embedchain----查询配置_一点知趣的博客-CSDN博客

下一篇文章:

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一点知趣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值