From d107e2998fbc8937eb4e5b5062b3cadb8a33c082 Mon Sep 17 00:00:00 2001 From: Jizu Date: Wed, 22 Apr 2026 21:55:33 +0800 Subject: [PATCH] feat: add dspy v3.1.3 container image for OC9 --- frameworks/dspy/Dockerfile | 11 +++++++++ frameworks/dspy/README.md | 48 ++++++++++++++++++++++++++++++++++++++ frameworks/dspy/test.sh | 42 +++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 frameworks/dspy/Dockerfile create mode 100644 frameworks/dspy/README.md create mode 100755 frameworks/dspy/test.sh diff --git a/frameworks/dspy/Dockerfile b/frameworks/dspy/Dockerfile new file mode 100644 index 0000000..580553b --- /dev/null +++ b/frameworks/dspy/Dockerfile @@ -0,0 +1,11 @@ +FROM opencloudos/opencloudos9-minimal:latest + +LABEL maintainer="contributor " +LABEL org.opencontainers.image.source="https://gitee.com/OpenCloudOS/ai-agent-container" +LABEL org.opencontainers.image.description="DSPy 3.1.3 on OpenCloudOS 9" + +RUN dnf install -y python3.11 python3.11-pip && dnf clean all && rm -rf /var/cache/yum/* + +RUN pip3.11 install --no-cache-dir dspy==3.1.3 + +CMD ["python3.11"] diff --git a/frameworks/dspy/README.md b/frameworks/dspy/README.md new file mode 100644 index 0000000..27a355a --- /dev/null +++ b/frameworks/dspy/README.md @@ -0,0 +1,48 @@ +# DSPy on OpenCloudOS 9 + +## 基本信息 + +| 项目 | 详情 | +|------|------| +| **框架版本** | 3.1.3 | +| **基础镜像** | opencloudos/opencloudos9-minimal:latest | +| **Python 版本** | 3.11 | +| **CUDA 版本** | N/A(纯 CPU) | +| **开源地址** | https://github.com/stanfordnlp/dspy | + +## 框架简介 + +DSPy(Declarative Self-improving Python)是由 Stanford NLP 开发的框架,用于以编程方式(而非提示词)构建模块化 AI 系统。支持构建分类器、RAG 管道和 Agent 循环,并提供自动优化 prompt 和权重的算法。 + +## 构建 + +```bash +docker build -t oc9-dspy:3.1.3 . +``` + +## 使用示例 + +```bash +# 验证安装 +docker run --rm oc9-dspy:3.1.3 python3.11 -c "import dspy; print(dspy.__version__)" + +# 交互式使用 +docker run -it --rm oc9-dspy:3.1.3 python3.11 +``` + +```python +import dspy + +# 配置 LM(以 OpenAI 为例) +lm = dspy.LM('openai/gpt-4o-mini', api_key='your-api-key') +dspy.configure(lm=lm) + +# 定义 Signature 并调用 +qa = dspy.Predict('question -> answer') +result = qa(question="What is OpenCloudOS?") +print(result.answer) +``` + +## 已知问题 + +- 无 diff --git a/frameworks/dspy/test.sh b/frameworks/dspy/test.sh new file mode 100755 index 0000000..8e9b34a --- /dev/null +++ b/frameworks/dspy/test.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -e + +echo "=== DSPy 3.1.3 基础功能测试 ===" + +# 1. 验证框架可正常导入并检查版本 +echo -n "检查 import 和版本... " +python3.11 -c "import dspy; v = dspy.__version__; assert v == '3.1.3', f'版本不匹配: {v}'; print(v)" && echo "✓ 通过" || { echo "✗ 失败"; exit 1; } + +# 2. 验证 Signature 定义 +echo -n "检查 Signature 定义... " +python3.11 -c " +from dspy import Signature, InputField, OutputField + +class BasicQA(Signature): + question = InputField(desc='a question') + answer = OutputField(desc='an answer') + +assert 'question' in BasicQA.input_fields +assert 'answer' in BasicQA.output_fields +print('Signature 正常') +" && echo "✓ 通过" || { echo "✗ 失败"; exit 1; } + +# 3. 验证 Predict 模块创建 +echo -n "检查 Predict 模块... " +python3.11 -c " +import dspy +predictor = dspy.Predict('question -> answer') +assert predictor is not None +print('Predict 模块正常') +" && echo "✓ 通过" || { echo "✗ 失败"; exit 1; } + +# 4. 验证 ChainOfThought 模块 +echo -n "检查 ChainOfThought 模块... " +python3.11 -c " +import dspy +cot = dspy.ChainOfThought('question -> answer') +assert cot is not None +print('ChainOfThought 模块正常') +" && echo "✓ 通过" || { echo "✗ 失败"; exit 1; } + +echo "=== 所有测试通过 ===" -- Gitee