8000 Add dictionaries as parameters for LLMFunctions by Seb-Ltz · Pull Request #113 · StanfordSpezi/SpeziLLM · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add dictionaries as parameters for LLMFunctions #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 28, 2025

Conversation

Seb-Ltz
Copy link
Collaborator
@Seb-Ltz Seb-Ltz commented Apr 25, 2025

Add dictionaries as parameters for LLMFunctions

♻️ Current situation & Problem

While developing test LLMFunctions, I discovered that Swift dictionaries are currently unsupported by SpeziLLM unless a custom parameter type is defined manually.

To simplify this, this PR proposes adding support for dictionary types in @Parameter declarations, allowing to write:

@Parameter(description: "Int Dictionary Parameter")
var intDictionaryParameter: [String: Int]

without needing to create a custom type for a dictionary.

⚙️ Release Notes

This PR adds support for the following Swift dictionary types as LLMFunction parameters, using Swift's standard type protocols (except for Bool):

  • [String: Int] dictionaries
  • [String: Double (or Float)] dictionaries
  • [String: Bool] dictionaries
  • [String: String] dictionaries

Each dictionary is represented as a JSON Schema object, with the corresponding value type defined under additionalProperties.

📚 Documentation

Documentation has been added.

✅ Testing

Unit tests have been written, following a similar structure than the unit tests for the array parameters.

Furthermore, all 4 dictionary types implemented (string, number, integers, bools) have been tested manually, using some test LLMFunctions and OpenAI's completion and Realtime API.

📝 Code of Conduct & Contributing Guidelines

By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

Copy link
codecov bot commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 44.22%. Comparing base (64ea041) to head (e5fc544).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../LLMFunctionParameterWrapper+DictionaryTypes.swift 87.50% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #113      +/-   ##
==========================================
+ Coverage   43.49%   44.22%   +0.73%     
==========================================
  Files          67       68       +1     
  Lines         476      484       +8     
==========================================
+ Hits          207      214       +7     
- Misses        269      270       +1     
Files with missing lines Coverage Δ
.../LLMFunctionParameterWrapper+DictionaryTypes.swift 87.50% <87.50%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64ea041...e5fc544. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member
@philippzagar philippzagar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic job @Seb-Ltz, only had some minor thoughts! 🚀

@Seb-Ltz
Copy link
Collaborator Author
Seb-Ltz commented Apr 28, 2025

Thank you @philippzagar for the PR review! 🚀

@philippzagar philippzagar enabled auto-merge (squash) April 28, 2025 18:54
@philippzagar philippzagar disabled auto-merge April 28, 2025 22:01
@philippzagar philippzagar merged commit 276cecb into StanfordSpezi:main Apr 28, 2025
19 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Project Planning Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants
0