| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  | from enum import Enum | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from pydantic import BaseModel, ValidationInfo, field_validator | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TracingProviderEnum(Enum): | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  |     LANGFUSE = "langfuse" | 
					
						
							|  |  |  |     LANGSMITH = "langsmith" | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BaseTracingConfig(BaseModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Base model class for tracing | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  |     ... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LangfuseConfig(BaseTracingConfig): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Model class for Langfuse tracing config. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  |     public_key: str | 
					
						
							|  |  |  |     secret_key: str | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  |     host: str = "https://api.langfuse.com" | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @field_validator("host") | 
					
						
							| 
									
										
										
										
											2024-09-11 16:40:52 +08:00
										 |  |  |     @classmethod | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  |     def set_value(cls, v, info: ValidationInfo): | 
					
						
							|  |  |  |         if v is None or v == "": | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  |             v = "https://api.langfuse.com" | 
					
						
							|  |  |  |         if not v.startswith("https://") and not v.startswith("http://"): | 
					
						
							|  |  |  |             raise ValueError("host must start with https:// or http://") | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return v | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LangSmithConfig(BaseTracingConfig): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Model class for Langsmith tracing config. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  |     api_key: str | 
					
						
							|  |  |  |     project: str | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  |     endpoint: str = "https://api.smith.langchain.com" | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @field_validator("endpoint") | 
					
						
							| 
									
										
										
										
											2024-09-11 16:40:52 +08:00
										 |  |  |     @classmethod | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  |     def set_value(cls, v, info: ValidationInfo): | 
					
						
							|  |  |  |         if v is None or v == "": | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  |             v = "https://api.smith.langchain.com" | 
					
						
							|  |  |  |         if not v.startswith("https://"): | 
					
						
							|  |  |  |             raise ValueError("endpoint must start with https://") | 
					
						
							| 
									
										
										
										
											2024-06-26 17:33:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return v | 
					
						
							| 
									
										
										
										
											2024-11-08 14:43:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OPS_FILE_PATH = "ops_trace/" | 
					
						
							|  |  |  | OPS_TRACE_FAILED_KEY = "FAILED_OPS_TRACE" |