Skip to content
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

feat: HTTP Generator #32

Merged
merged 9 commits into from
Jan 30, 2025
Merged

feat: HTTP Generator #32

merged 9 commits into from
Jan 30, 2025

Conversation

monoxgas
Copy link
Contributor

@monoxgas monoxgas commented Jan 29, 2025

  • Added a new HTTPGenerator with http! to support using arbitrary web requests as a generator.
  • Defined a schema/spec to use for the .spec parameter of this generator with the ability to decode it from yaml, json, or base64-encoded yaml/json on assignment or when using a generator id.

Example use:

import rigging as rg

spec = r"""
request:
  url: "https://{{ model }}.crucible.dreadnode.io/submit"
  headers:
    "X-Api-Key": "{{ api_key }}"
    "Content-Type": "application/json"
  transforms:
    - type: "json"
      pattern: {
        "data": "$content"
      }
response:
  transforms:
    - type: "jsonpath"
      pattern: $.output
"""

crucible = rg.get_generator("http!spanglish,api_key=<key>")
crucible.spec = spec

chat = await crucible.chat("How are you?").run()

print(chat.conversation)

print(crucible.to_identifier())

Generated Summary

  • Added new dependencies: jsonpath-ng and ruamel-yaml in pyproject.toml.
  • Introduced a new HTTPGenerator for mapping messages to HTTP requests and responses in rigging/generator/http.py.
  • Created a comprehensive structure for defining HTTP request and response specifications using HTTPSpec, including transformation mechanisms for both inputs and outputs.
  • Implemented error handling within the generator with a custom ProcessingError to manage exceptions during processing.
  • Enhanced the request body construction to support varying transformation types (e.g., JSON and Jinja) based on user-defined contexts.
  • Added tests for HTTPSpec, covering key functionalities including request creation, response parsing, and error scenarios.
  • Updated the __init__.py to include the new HTTPGenerator and modified imports to include the generator.
  • No breaking changes; the updates enhance the ability to interact with HTTP APIs within the existing framework.

This summary was generated with ❤️ by rigging

Copy link

cloudflare-workers-and-pages bot commented Jan 29, 2025

Deploying rigging-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: cdcb911
Status: ✅  Deploy successful!
Preview URL: https://f484a861.rigging-docs.pages.dev
Branch Preview URL: https://feature-http-generator.rigging-docs.pages.dev

View logs


# Spec types

InputTransform = t.Literal["json", "jinja"]

Choose a reason for hiding this comment

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

should the input also include jsonpath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think of jsonpath as being an extractor mechanism (removing information), and json as formatting (adding information).

Def open to some example use cases though, lots of options for blending.

@monoxgas monoxgas merged commit f04f35b into main Jan 30, 2025
5 checks passed
@monoxgas monoxgas deleted the feature/http-generator branch January 30, 2025 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants