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

XFEstudio/gpt4free

Update discord bot

880ed5f1
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +54 -1
Modified g4f/api/__init__.py +53 -0
@@ -1609,6 +1609,59 @@ class Api:
1609 1609 HTTP_500_INTERNAL_SERVER_ERROR: {"model": ErrorResponseModel},
1610 1610 }
1611 1611
1612
1613 @self.app.get("/text/{url:path}", responses={
1614 HTTP_200_OK: {"content": {"text/plain": {}}},
1615 HTTP_401_UNAUTHORIZED: {"model": ErrorResponseModel},
1616 HTTP_404_NOT_FOUND: {"model": ErrorResponseModel},
1617 HTTP_500_INTERNAL_SERVER_ERROR: {"model": ErrorResponseModel},
1618 })
1619 async def convert_url(
1620 request: Request,
1621 url: str
1622 ):
1623 """Convert a URL to Markdown using MarkItDown.
1624
1625 The full URL (including scheme) is passed in the path, e.g.:
1626 GET /markitdown/https://example.com/page
1627
1628 Query strings are preserved by reading them from the incoming
1629 request and re-appending them to the target URL, e.g.:
1630 GET /markitdown/https://example.com/page?foo=bar
1631 """
1632 # FastAPI strips the query string from the {url:path} parameter,
1633 # so re-attach it from the incoming request when present.
1634 query_string = request.url.query
1635 if query_string and "?" not in url:
1636 url = f"{url}?{query_string}"
1637 elif query_string:
1638 # url already contains a '?', append remaining params with '&'
1639 url = f"{url}&{query_string}"
1640 if not url.startswith(("http://", "https://")):
1641 return ErrorResponse.from_message(
1642 f"Invalid URL: {url}. URL must start with http:// or https://",
1643 HTTP_422_UNPROCESSABLE_CONTENT,
1644 )
1645 try:
1646 from g4f.integration.markitdown import MarkItDown
1647
1648 md = MarkItDown()
1649 result = md.convert_url(url)
1650 text = result.text_content
1651 if asyncio.iscoroutine(text):
1652 text = await text
1653 return Response(text, media_type="text/plain")
1654 except ImportError as e:
1655 logger.exception(e)
1656 return ErrorResponse.from_exception(
1657 e, None, HTTP_500_INTERNAL_SERVER_ERROR
1658 )
1659 except Exception as e:
1660 logger.exception(e)
1661 return ErrorResponse.from_exception(
1662 e, None, HTTP_500_INTERNAL_SERVER_ERROR
1663 )
1664
1612 1665 @self.app.get("/markitdown/{url:path}", responses=responses)
1613 1666 async def convert_url(
1614 1667 request: Request,
Modified g4f/client/factory.py +1 -1
@@ -132,7 +132,7 @@ class AbstractClientFactory:
132 132 ):
133 133 api_key = AppConfig.g4f_api_key
134 134 return create_custom_provider(
135 base_url=config.get("baseUrl")
135 base_url=config.get("baseUrl", config.get("backupUrl"))
136 136 if cls.is_provider_api_key(api_key)
137 137 or config.get("backupUrl") is None
138 138 else config.get("backupUrl", config.get("baseUrl")),