Skip to main content

A Python package for executing graph generation from textual inputs.

Project description

PyPI version License: MIT Downloads

eKnowledge

eKnowledge is a Python package designed to facilitate the generation of knowledge graphs from textual inputs using various language models. The package leverages the power of NLP to extract relationships and constructs from code snippets or any other structured text.

Installation

To install eKnowledge, you can use pip:

pip install eknowledge

Usage

eKnowledge supports various language models for processing input text, including locally hosted models and remote API-based models. Below is an example using the ChatOllama model, which requires a locally downloaded model from ollama.com. The recommended model for local usage is "codestral:22b-v0.1-q2_K".

Example with Local Language Model (ChatOllama)

from eknowledge import execute_graph_generation
from langchain_community.chat_models import ChatOllama
from langchain_huggingface import HuggingFaceEmbeddings

# Configure the language model
MISTRAL_MODEL = "codestral:22b-v0.1-q2_K"
MAX_TOKENS = 1500

# Initialize the model with the desired configuration
llm = ChatOllama(model=MISTRAL_MODEL, max_tokens=MAX_TOKENS)

# Sample Python code to process
input_text = """
def factorial(x):
    if x == 1:
        return 1
    else:
        return (x * factorial(x-1))

num = 3
print("The factorial of", num, "is", factorial(num))
"""

# Generate the knowledge graph
embed = HuggingFaceEmbeddings()
graph = execute_graph_generation(input_text, llm, embed, max_attempts=1)

print(graph)
# Output: 
# [
#   {
#       'from_node': 'factorial', 
#       'relation': 'depends_on', 
#       'to_node': 'x'
#   }, 
#   {
#       'from_node': 'factorial', 
#       'relation': 'composed_of', 
#       'to_node': 'factorial(x-1)'
#   }, 
#   {
#       'from_node': 'num', 
#       'relation': 'is_a', 
#       'to_node': '3'
#   }, 
#   {
#       'from_node': 'factorial(num)', 
#       'relation': 'used_for', 
#       'to_node': 'print function'
#   }
#]

Features

  • Supports multiple language models including remote API and local executions.
  • Extracts structured knowledge from unstructured text.
  • Can be used in various domains like academic research, software development, and data science.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

This project is licensed under the MIT License.

The codestral model is licensed under The Mistral AI Non-Production License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eknowledge-0.1.3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

eknowledge-0.1.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file eknowledge-0.1.3.tar.gz.

File metadata

  • Download URL: eknowledge-0.1.3.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for eknowledge-0.1.3.tar.gz
Algorithm Hash digest
SHA256 295730d5d5754697a47c292bef60fe91bc171908137a141c901b59ab0c3825aa
MD5 8b20d8c14df6e7a56f1fe078c7e3a719
BLAKE2b-256 f52bf1879af2d36b58ea915283d15ad5752ea057f333dcc1edd586d3dbbef858

See more details on using hashes here.

File details

Details for the file eknowledge-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: eknowledge-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for eknowledge-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8ad512feb831963ccee5a3b885dc9b2e71fc9ee51e565e1f21b49213b2ab62c9
MD5 6b88e52754bd83155f174ebc74ac947f
BLAKE2b-256 a69962d8d4bf0eadfd285a8d2e4d6d67e446b04b61cac3cd06317e637df89d70

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page