diff --git a/python/bench/tracing_script.py b/python/bench/tracing_script.py new file mode 100644 index 000000000..30084db9f --- /dev/null +++ b/python/bench/tracing_script.py @@ -0,0 +1,44 @@ +import os +os.environ["LANGCHAIN_PROJECT"] = "llm_messages_test_py" +os.environ["LANGSMITH_USE_PYO3_CLIENT"] = "true" + +from langsmith import traceable + +@traceable +def format_prompt(subject): + return [ + { + "role": "system", + "content": "You are a helpful assistant.", + }, + { + "role": "user", + "content": f"What's a good name for a store that sells {subject}?" + } + ] + +@traceable(run_type="llm") +def invoke_llm(messages): + return { + "choices": [ + { + "message": { + "role": "assistant", + "content": "Sure, how about 'Rainbow Socks'?" + } + } + ] +} + +@traceable +def parse_output(response): + return response["choices"][0]["message"]["content"] + +@traceable +def run_pipeline(): + messages = format_prompt("colorful socks") + response = invoke_llm(messages) + return parse_output(response) + +if __name__ == "__main__": + run_pipeline() \ No newline at end of file diff --git a/python/langsmith/_internal/_operations.py b/python/langsmith/_internal/_operations.py index 66decff0f..89d5f12fc 100644 --- a/python/langsmith/_internal/_operations.py +++ b/python/langsmith/_internal/_operations.py @@ -141,6 +141,27 @@ def serialize_run_dict( attachments=attachments if attachments is not None else None, ) +def serialize_run_dict_for_compressed_ingest( + operation: Literal["post", "patch"], payload: dict +): + inputs = payload.pop("inputs", None) + outputs = payload.pop("outputs", None) + events = payload.pop("events", None) + attachments = payload.pop("attachments", None) + serialized = ... + extra = ... + return SerializedRunOperation( + operation=operation, + id=payload["id"], + trace_id=payload["trace_id"], + _none=_dumps_json(payload), + inputs=_dumps_json(inputs) if inputs is not None else None, + outputs=_dumps_json(outputs) if outputs is not None else None, + events=_dumps_json(events) if events is not None else None, + attachments=attachments if attachments is not None else None, + ) + + def combine_serialized_queue_operations( ops: list[Union[SerializedRunOperation, SerializedFeedbackOperation]], diff --git a/python/langsmith/client.py b/python/langsmith/client.py index e422dbec1..c47438cbe 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -1287,9 +1287,10 @@ def create_run( run_create.get("trace_id") is not None and run_create.get("dotted_order") is not None ): - if self._pyo3_client is not None: - self._pyo3_client.create_run(run_create) - elif self.tracing_queue is not None: + # if self._pyo3_client is not None: + # print("RUN_CREATE", run_create) + # self._pyo3_client.create_run(run_create) + if self.tracing_queue is not None: serialized_op = serialize_run_dict("post", run_create) self.tracing_queue.put( TracingQueueItem(run_create["dotted_order"], serialized_op) @@ -1753,9 +1754,11 @@ def update_run( if data["extra"]: self._insert_runtime_env([data]) - if self._pyo3_client is not None: - self._pyo3_client.update_run(data) - elif use_multipart and self.tracing_queue is not None: + print("UPDATE_RUN", data) + + # if self._pyo3_client is not None: + # self._pyo3_client.update_run(data) + if use_multipart and self.tracing_queue is not None: # not collecting attachments currently, use empty dict serialized_op = serialize_run_dict(operation="patch", payload=data) self.tracing_queue.put(