{"id":20744002,"url":"https://github.com/zylon-ai/pgpt-python","last_synced_at":"2025-10-14T15:30:29.910Z","repository":{"id":218610678,"uuid":"746876753","full_name":"zylon-ai/pgpt-python","owner":"zylon-ai","description":"PrivateGPT Python SDK","archived":false,"fork":false,"pushed_at":"2024-08-02T09:21:13.000Z","size":58,"stargazers_count":115,"open_issues_count":9,"forks_count":23,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-08-02T22:43:39.083Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zylon-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-22T21:05:24.000Z","updated_at":"2025-07-30T13:52:54.000Z","dependencies_parsed_at":"2024-01-23T01:10:46.246Z","dependency_job_id":"417710fc-0f6d-41d4-bea9-7e3c4290940b","html_url":"https://github.com/zylon-ai/pgpt-python","commit_stats":{"total_commits":13,"total_committers":4,"mean_commits":3.25,"dds":0.5384615384615384,"last_synced_commit":"07593deb965a66cc665a1313a608030f8be9ac87"},"previous_names":["imartinez/pgpt-python","zylon-ai/pgpt-python","imartinez/pgpt_python"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zylon-ai/pgpt-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zylon-ai%2Fpgpt-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zylon-ai%2Fpgpt-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zylon-ai%2Fpgpt-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zylon-ai%2Fpgpt-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zylon-ai","download_url":"https://codeload.github.com/zylon-ai/pgpt-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zylon-ai%2Fpgpt-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019321,"owners_count":26086711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T07:13:57.784Z","updated_at":"2025-10-14T15:30:29.594Z","avatar_url":"https://github.com/zylon-ai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python SDK for PrivateGPT API\n\n**pgpt_python** is an open-source Python SDK designed to interact with the PrivateGPT API. PrivateGPT is a popular AI Open Source project that provides secure and private access to advanced natural language processing capabilities. This SDK simplifies the integration of PrivateGPT into Python applications, allowing developers to harness the power of PrivateGPT for various language-related tasks.\n\nThis SDK has been created using [Fern](https://buildwithfern.com/).\n\n## Installation\n\nTo install the pgpt_python SDK, use the following pip command:\n\n```bash\npip install pgpt_python\n```\n\n## Getting Started\n\nTo begin using pgpt_python with the PrivateGPT API, follow these steps:\n\n1. **Import the PrivateGPTApi class:**\n\n    ```python\n    from pgpt_python.client import PrivateGPTApi\n    ```\n\n2. **Create a PrivateGPTApi instance. Point it to your PrivateGPT url:**\n\n    ```python\n    client = PrivateGPTApi(base_url=\"http://localhost:8001\")\n    ```\n\n3. Certainly! Here's the completed \"Perform API calls\" section:\n\n## Perform API Calls\n\nOnce you have set up the PrivateGPTApi instance, you can perform various API calls using the pgpt_python SDK. Below are examples of common API calls:\n\n### 1. **Health Check:**\n\n```python\nprint(client.health.health())\n\n\u003e status='ok'\n```\n\nThis call checks the health of the PrivateGPT API and returns information about its status.\n\n### 2. **Completion:**\n\n```python\nprompt_result = client.contextual_completions.prompt_completion(\n    prompt=\"Answer with just the result: 2+2\"\n)\nprint(prompt_result.choices[0].message.content)\n\n\u003e The answer is 4.\n```\n\nThis call performs contextual completions based on the provided prompt and retrieves the completion result.\n\n### 3. **Streaming Completion:**\n\n```python\nfor i in client.contextual_completions.prompt_completion_stream(\n    prompt=\"Answer with just the result: 2+2\"\n):\n    print(i.choices[0].delta.content, end=\"\")\n\n\u003e The answer i...\n```\n\nThis example demonstrates contextual completions using a streaming approach, allowing you to process results incrementally.\n\n### 4. **Chat Completion:**\n\n```python\nchat_result = client.contextual_completions.chat_completion(\n    messages=[{\"role\": \"user\", \"content\": \"Answer with just the result: 2+2\"}]\n)\nprint(chat_result.choices[0].message.content)\n\n\u003e The answer is 4.\n```\n\nPerform a chat completion using a list of messages to simulate a conversation.\n\n### 5. **Streaming Chat Completion:**\n\n```python\nfor i in client.contextual_completions.chat_completion_stream(\n    messages=[{\"role\": \"user\", \"content\": \"Answer with just the result: 2+2\"}]\n):\n    print(i.choices[0].delta.content, end=\"\")\n\n\u003e The answer i...\n```\n\nThis example demonstrates streaming chat completions using a streaming approach, allowing you to process results incrementally.\n\n### 6. **Embeddings:**\n\n```python\nembedding_result = client.embeddings.embeddings_generation(input=\"Hello world\")\nprint(embedding_result.data[0].embedding)\n\n\u003e [0.015196125954389572, -0.022570695728063583, 0.008547102101147175, -0.07417059689760208, 0.0038364222273230553, ... ]\n```\n\nRetrieve embeddings for a given input using synchronous embeddings generation.\n\n### 7. **Ingestion of Text:**\n\n```python\ntext_to_ingest = \"Books bombarded his shoulder, ... (your long text here)\"\ningested_text_doc_id = (\n    client.ingestion.ingest_text(file_name=\"Fahrenheit 451\", text=text_to_ingest)\n    .data[0]\n    .doc_id\n)\nprint(\"Ingested text doc id: \", ingested_text_doc_id)\n\n\u003e Ingested text doc id:  8cfc93fa-01dd-4644-82d4-e12dfff54dcf\n```\n\nIngest text content and obtain a document ID for future reference.\n\n### 8. **Ingestion of File:**\n\n```python\nwith open(\"example_file.txt\", \"rb\") as f:\n    ingested_file_doc_id = client.ingestion.ingest_file(file=f).data[0].doc_id\nprint(\"Ingested file doc id: \", ingested_file_doc_id)\n\n\u003e Ingested file doc id:  e2989f56-1729-4557-b30a-e4b023628629\n```\n\nIngest a file and obtain a document ID for future reference.\n\n### 9. **List Ingested Documents:**\n\n```python\nfor doc in client.ingestion.list_ingested().data:\n    print(doc.doc_id)\n\n\u003eList ingested documents\ne2989f56-1729-4557-b30a-e4b023628629\n8cfc93fa-01dd-4644-82d4-e12dfff54dcf\n```\n\nRetrieve a list of ingested documents along with their document IDs.\n\n### 10. **Chunks Retrieval:**\n\n```python\nchunks_result = client.context_chunks.chunks_retrieval(text=\"Pigeon fluttering\")\nprint(chunks_result.data[0].text)\n\n\u003e A book lit, almost obediently, like a white pigeon, in his hands, wings fluttering.\n```\n\nRetrieve related chunks of text from ingested docs based on a specified query.\n\n### 11. **Contextual Completion:**\n\n```python\nresult = client.contextual_completions.prompt_completion(\n    prompt=\"What did Montage do?\",\n    use_context=True,\n    context_filter={\"docs_ids\": [\"8cfc93fa-01dd-4644-82d4-e12dfff54dcf\"]},\n    include_sources=True,\n).choices[0]\n\nprint(\"\\n\u003eContextual completion:\")\nprint(result.message.content)\nprint(f\" # Source: {result.sources[0].document.doc_metadata['file_name']}\")\n\n\u003e Montage was surrounded by falling books when one of them landed in his hands.\n  Source: Fahrenheit 451\n```\n\nPerform a contextual completion using the specified context from ingested documents, including in the response the sources used during inference.\n\n### 12. **Deletion of Ingested Documents:**\n\n```python\nclient.ingestion.delete_ingested(\"8cfc93fa-01dd-4644-82d4-e12dfff54dcf\")\nclient.ingestion.delete_ingested(\"e2989f56-1729-4557-b30a-e4b023628629\")\n```\n\nDelete previously ingested documents using their document IDs.\n\n### 13.  Recipes\n\nThe SDK also provides functionality for defined use cases called [`recipes`](https://docs.privategpt.dev/recipes/getting-started/quickstart).\n\n#### 1. Summarize recipe\nSummarize is a recipe that you will be able to summarise ingest a text on the spot or stored files. You will be able to enter extra instructions, customize the system prompt or define a file context to filter which files will be used to generate the summary.\n\n##### Summarize\n```python\nsummary_result = client.recipes.summarize.summarize(\n    text=(\n        \"Lorem Ipsum is simply dummy text of the printing and typesetting industry. \"\n        \"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, \"\n        \"when an unknown printer took a galley of type and scrambled it to make a type specimen book.\"\n    ),\n    instructions=(\n        \"Summarize the text to 1 sentence.\"\n    )\n)\nprint(summary_result.summary)\n\n\u003e Lorem Ipsum has been a standard dummy text in the printing industry since the 1500s.\n```\n\n##### Streaming summarize\n\n```python\nfor i in client.recipes.summarize.summarize_stream(\n    text=(\n        \"Lorem Ipsum is simply dummy text of the printing and typesetting industry. \"\n        \"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, \"\n        \"when an unknown printer took a galley of type and scrambled it to make a type specimen book.\"\n    ),\n    instructions=(\n        \"Summarize the text to 1 sentence.\"\n    )\n):\n    # Print content in an incremental way\n    print(i.choices[0].delta.content, end=\"\")\n\n\u003e Lorem Ipsum has been a standard dummy text...\n```\n\n## Examples\n\nThe provided `examples_script.py` showcases various features of the pgpt_python SDK. Feel free to explore and modify this script to suit your specific use cases.\n\n## Documentation\n\nFor detailed information on available methods and their parameters, refer to the [official documentation](https://docs.privategpt.dev/api-reference/overview/sd-ks).\n\n## Contributing\n\nWe welcome contributions from the community! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the Apache License.\n\n## Acknowledgments\n\n- [Fern](https://buildwithfern.com/) - For providing a powerful SDK generation tool, and supporting PrivateGPT with a free forever license.\n- [PrivateGPT Community](https://discord.gg/bK6mRVpErU) - For being the fuel of PrivateGPT and providing valuable feedback.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzylon-ai%2Fpgpt-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzylon-ai%2Fpgpt-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzylon-ai%2Fpgpt-python/lists"}