XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Add estimated_cost to response model

08f1dc58
hlohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

3 个文件 +18 -7
Modified g4f/client/stubs.py +5 -0
@@ -58,6 +58,7 @@ class UsageModel(BaseModel):
58 58 prompt_tokens_details: PromptTokenDetails
59 59 completion_tokens_details: CompletionTokenDetails
60 60 cache: Optional[str] = None
61 estimated_cost: Optional[float] = None
61 62
62 63 @classmethod
63 64 def model_construct(
@@ -67,6 +68,9 @@ class UsageModel(BaseModel):
67 68 total_tokens=0,
68 69 prompt_tokens_details=None,
69 70 completion_tokens_details=None,
71 estimated_cost=None,
72 market_cost=None,
73 pollen_cost=None,
70 74 **kwargs,
71 75 ):
72 76 return super().model_construct(
@@ -81,6 +85,7 @@ class UsageModel(BaseModel):
81 85 completion_tokens_details=CompletionTokenDetails.model_construct(
82 86 **completion_tokens_details if completion_tokens_details else {}
83 87 ),
88 estimated_cost=estimated_cost or market_cost or pollen_cost,
84 89 **kwargs,
85 90 )
86 91
Modified g4f/config.py +5 -5
@@ -29,7 +29,7 @@ def get_config_dir() -> Path:
29 29
30 30 DEFAULT_PORT = 1337
31 31 DEFAULT_TIMEOUT = 600
32 DEFAULT_STREAM_TIMEOUT = 120
32 DEFAULT_STREAM_TIMEOUT = 300
33 33
34 34 PACKAGE_NAME = "g4f"
35 35 CONFIG_DIR = get_config_dir()
@@ -54,10 +54,10 @@ class AppConfig:
54 54 ignored_providers: Optional[list[str]] = None
55 55 g4f_api_key: Optional[str] = None
56 56 ignore_cookie_files: bool = False
57 model: str = None
58 provider: str = None
59 media_provider: str = None
60 proxy: str = None
57 model: Optional[str] = None
58 provider: Optional[str] = None
59 media_provider: Optional[str] = None
60 proxy: Optional[str] = None
61 61 gui: bool = False
62 62 demo: bool = False
63 63 timeout: int = DEFAULT_TIMEOUT
Modified g4f/mcp/pa_provider.py +8 -2
@@ -512,6 +512,7 @@ def _make_safe_globals(
512 512 allowed: FrozenSet[str] = SAFE_MODULES,
513 513 stdout_buf: Optional[io.StringIO] = None,
514 514 stderr_buf: Optional[io.StringIO] = None,
515 file_path: Optional[Path] = None,
515 516 ) -> Dict[str, Any]:
516 517 """Return a ``globals`` dict suitable for sandboxed ``exec``."""
517 518 workspace = get_workspace_dir()
@@ -529,7 +530,12 @@ def _make_safe_globals(
529 530 """open() restricted to the workspace directory."""
530 531 path = Path(file)
531 532 if not path.is_absolute():
532 path = workspace / "pa-providers" / path
533 parent = file_path.parent if file_path else workspace
534 while parent != parent.parent:
535 path = parent / path.name
536 if path.exists():
537 break
538 parent = parent.parent
533 539 try:
534 540 resolved = path.resolve()
535 541 ws_resolved = workspace.resolve()
@@ -645,7 +651,7 @@ def execute_safe_code(
645 651 stderr_buf = _LimitedStringIO(MAX_OUTPUT_BYTES)
646 652
647 653 safe_globals = _make_safe_globals(
648 allowed_modules, stdout_buf=stdout_buf, stderr_buf=stderr_buf
654 allowed_modules, stdout_buf=stdout_buf, stderr_buf=stderr_buf, file_path=None if file_path is None else Path(file_path)
649 655 )
650 656 if file_path is not None:
651 657 safe_globals["__file__"] = str(Path(file_path).resolve())