提示工程自动优化框架

2024-11-11T00:00:00Z | 3分钟阅读 | 更新于 2024-11-11T00:00:00Z

提示工程自动优化框架

DSPy: Programming—not prompting—Language Models

DSPy简介

  • 项目主站:https://dspy.ai
  • 项目仓库:https://github.com/stanfordnlp/dspy
  • DSPy(Declarative Self-improving Language Programs(in Python)),即声明式自改进语言程序,是一个对语言模型Prompt和权重进行算法优化的框架。DSPy强调通过编程而非硬编码Prompt构建基于LLM的应用。
  • 创造了一种提示词工程的新范式,对目前提示词工程中的共识问题(如提示词的脆弱性、迭代成本高、缺乏系统方化方法、范式繁多、依靠人类经验)等诸多问题,给出了新的解决思路。

DSPy相关文章

用DSPy写最佳推理轨迹搜索DOTS,让LLM能动态推理

  • 论文:https://arxiv.org/pdf/2410.03864
  • DOTS(Dynamic Optimal Trajectory Search),通过最佳推理轨迹搜索,显著提升LLMs的动态推理能力
  • DOTS方法的核心创新在于,摒弃了传统方法中对所有问题采用统一、静态推理策略的做法,转而引入了一种动态的、自适应的推理机制。
  • DOTS方法的核心在于通过动态选择最优推理轨迹来增强LLMs的推理能力。
  • 包含三个关键步骤:定义原子推理动作模块、搜索最优推理轨迹、以及训练LLM的动态规划能力。
  • 项目仓库:https://github.com/MurongYue/DOTS 空的

DSPy 简单示例

import dspy

ollama_port = 11434 
ollama_url = f"http://192.168.190.253:{ollama_port}"
llm = dspy.LM(model="ollama/qwen2.5:14b", api_base=ollama_url)
dspy.configure(lm=llm)
question="Which is larger, 9.8 or 9.11?"
print('question:',question)
print('')
## Example 1: simply call the LM with a string to give it a raw prompt
response=llm(messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": question}])
print('simply call the LM with a string to give it a raw prompt')
print(response)
print('')
## Example 2: Question answering with ChainOfThought
qa = dspy.ChainOfThought('question -> answer')
response = qa(question=question)
print('Question answering with ChainOfThought')
print(response.answer)

ChatGPT提示优化框架TextGrad

TextGrad简介

TextGrad相关文章

Weavel Ape

Weavel Ape简介

Weavel Ape相关文章

© 2024 - 2025 i68,爱六八,链接你我他-i68.ltd-随笔

关于我

i68,爱六八,链接你我他

我是一名热爱技术的开发人员,在这里我会记录一些关于技术或者生活上的事情。