Skip to content

Commit

Permalink
feat: add prompt sdk functionality to langsmith sdk (#864)
Browse files Browse the repository at this point in the history
Copying over functionality from the hub sdk to here

Also adds some new functionality and changing of terms, ex.
* refer to prompts as prompts instead of repos
* the ability to pull a prompt with the stored model
* list_prompts now accepts fields besides just limit and offset
* delete a prompt
* accepting a readme in push_prompt
  • Loading branch information
madams0013 authored Jul 17, 2024
2 parents 690b1ea + 5abf9bf commit 158b999
Show file tree
Hide file tree
Showing 8 changed files with 1,394 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Install dependencies
run: |
poetry install --with dev,lint
poetry run pip install -U langchain langchain-core
poetry run pip install -U langchain langchain-core langchain_anthropic langchain_openai
- name: Build ${{ matrix.python-version }}
run: poetry build
- name: Lint ${{ matrix.python-version }}
Expand Down
18 changes: 12 additions & 6 deletions _scripts/_fetch_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fetch and prune the Langsmith spec."""

import argparse
from pathlib import Path

Expand All @@ -19,7 +20,9 @@ def process_schema(sub_schema):
get_dependencies(schema, sub_schema["$ref"].split("/")[-1], new_components)
else:
if "items" in sub_schema and "$ref" in sub_schema["items"]:
get_dependencies(schema, sub_schema["items"]["$ref"].split("/")[-1], new_components)
get_dependencies(
schema, sub_schema["items"]["$ref"].split("/")[-1], new_components
)
for keyword in ["anyOf", "oneOf", "allOf"]:
if keyword in sub_schema:
for item in sub_schema[keyword]:
Expand All @@ -38,8 +41,6 @@ def process_schema(sub_schema):
process_schema(item)




def _extract_langsmith_routes_and_properties(schema, operation_ids):
new_paths = {}
new_components = {"schemas": {}}
Expand Down Expand Up @@ -98,20 +99,25 @@ def test_openapi_specification(spec: dict):
assert errors is None, f"OpenAPI validation failed: {errors}"


def main(out_file: str = "openapi.yaml", url: str = "https://web.smith.langchain.com/openapi.json"):
def main(
out_file: str = "openapi.yaml",
url: str = "https://web.smith.langchain.com/openapi.json",
):
langsmith_schema = get_langsmith_runs_schema(url=url)
parent_dir = Path(__file__).parent.parent
test_openapi_specification(langsmith_schema)
with (parent_dir / "openapi" / out_file).open("w") as f:
# Sort the schema keys so the openapi version and info come at the top
for key in ['openapi', 'info', 'paths', 'components']:
for key in ["openapi", "info", "paths", "components"]:
langsmith_schema[key] = langsmith_schema.pop(key)
f.write(yaml.dump(langsmith_schema, sort_keys=False))


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--url", type=str, default="https://web.smith.langchain.com/openapi.json")
parser.add_argument(
"--url", type=str, default="https://web.smith.langchain.com/openapi.json"
)
parser.add_argument("--output", type=str, default="openapi.yaml")
args = parser.parse_args()
main(args.output, url=args.url)
Loading

0 comments on commit 158b999

Please sign in to comment.