Skip to main content
Open In ColabOpen on GitHub

ChatLLM7

This documentation will help you get started with LLM7's chat models. For detailed documentation of all ChatLLM7 features and configurations, see the API reference. The ChatLLM7 class connects to LLM7's API-compatible endpoints.

Overviewโ€‹

Integration detailsโ€‹

ClassPackageLocalSerializableJS supportPackage downloadsPackage latest
ChatLLM7langchain_llm7โŒbetaโŒPyPI - DownloadsPyPI - Version

Model featuresโ€‹

Tool callingStructured outputJSON modeImage inputAudio inputVideo inputToken-level streamingNative asyncToken usageLogprobs
โŒโŒโŒโŒโŒโŒโœ…โœ…โœ…โŒ

Setupโ€‹

Installationโ€‹

Install the LangChain LLM7 integration package:

%pip install -qU langchain-llm7
     โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 65.2/65.2 kB 1.3 MB/s eta 0:00:00
 โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 423.3/423.3 kB 7.0 MB/s eta 0:00:00
 โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 443.6/443.6 kB 21.4 MB/s eta 0:00:00
[?25h

Instantiationโ€‹

Create a ChatLLM7 instance with your preferred parameters:

from langchain_llm7 import ChatLLM7

llm = ChatLLM7(
model_name="gpt-4o-mini-2024-07-18",
temperature=0.7,
max_tokens=300,
timeout=90,
streaming=True,
)

Invocationโ€‹

Basic chat completion example:

from langchain_core.messages import HumanMessage, SystemMessage

messages = [
SystemMessage(
content="You are a physics tutor. Explain concepts clearly and concisely."
),
HumanMessage(content="Explain quantum physics in simple terms"),
]

response = llm.invoke(messages)
response
API Reference:HumanMessage | SystemMessage
AIMessage(content='Quantum physics, also known as quantum mechanics, is the branch of physics that studies the behavior of matter and energy at very small scales, such as atoms and subatomic particles. Here are some key concepts explained in simple terms:\n\n1. **Quantization**: Energy and other properties are not continuous but come in small, discrete amounts called "quanta." For example, light can be thought of as being made up of tiny packets of energy called photons.\n\n2. **Wave-Particle Duality**: Particles, such as electrons, can exhibit properties of both particles and waves. This means they can behave like a small ball (particle) in some situations and like ripples on water (wave) in others.\n\n3. **Uncertainty Principle**: Proposed by Werner Heisenberg, this principle states that you cannot precisely know both the position and momentum of a particle at the same time. The more accurately you know one, the less accurately you can know the other.\n\n4. **Superposition**: Particles can exist in multiple states or configurations at once until they are observed. For example, an electron in an atom can be in several energy levels at the same time until a measurement is made.\n\n5. **Entanglement**: When particles become entangled, the state of one particle is linked to the state of another, no matter how far apart they are. Changing the state of one instantaneously affects the other, even across vast distances.\n\nIn summary, quantum physics reveals a strange and counterintuitive world where particles behave unpredictably, and our observations can influence what we see. It challenges our classical notions of how things should behave and has profound implications for technology, including quantum computing and cryptography.', additional_kwargs={}, response_metadata={}, id='run-3c71820b-8bf0-401f-ad2b-2efdb3a33a7a-0', usage_metadata={'input_tokens': 18, 'output_tokens': 305, 'total_tokens': 323})

Chainingโ€‹

Create a translation chain with a prompt template:

from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a scientific explainer. Break down {concept} for a {audience} audience.",
),
("human", "Explain: {query}"),
]
)

chain = prompt | llm
chain.invoke(
{
"concept": "quantum entanglement",
"audience": "high school",
"query": "What happens when particles become entangled?",
}
)
API Reference:ChatPromptTemplate
AIMessage(content='Sure! Let\'s break down quantum entanglement in a way that\'s easy to understand.\n\n### What is Quantum Entanglement?\n\nQuantum entanglement is a fascinating phenomenon that occurs when two or more particles become connected in such a way that the state of one particle is directly related to the state of the other, no matter how far apart they are. Itโ€™s like the particles are communicating with each other instantaneously, even if they are light-years apart!\n\n### How Does It Happen?\n\n1. **Creation of Entangled Particles**: \n   Imagine you have a pair of dice that are special: whenever you roll one die, the other die will always show the same number, no matter where they are. This is similar to how particles become entangled. They often become entangled during interactions, like when two particles collide and then separate.\n\n2. **Measurement**:\n   Once the particles are entangled, if you measure one particle (for example, checking its spin or polarization), you instantly know the state of the other particle. Itโ€™s as if you rolled one die and immediately knew what number the other die showed, even if itโ€™s far away.\n\n3. **Instant Connection**:\n   This "connection" between the particles is what makes entanglement so strange. If one particle is affected by something (like a measurement), it instantly affects its entangled partner, regardless of the distance separating them. This baffled even Einstein, who referred to it as "spooky action at a distance."\n\n### Why Is It Important?\n\n1. **Quantum Computing**: Entanglement is crucial for quantum computers, which use principles of quantum mechanics to process information in ways that traditional computers cannot. Entangled particles can be used to perform complex calculations much more efficiently.\n\n2. **Quantum Cryptography**: It also plays a role in secure communication methods. Because unmeasured entangled particles remain connected, any attempt to intercept the communication would disturb the entanglement and reveal that someone is snooping.\n\n3. **Understanding the Universe**: Studying entanglement helps scientists understand the fundamental laws of physics and the nature of reality itself, raising questions about what happens at the quantum level.\n\n### Conclusion\n\nIn summary, quantum entanglement is a remarkable connection between particles that transcends distance. Once entangled, the particles act as a single system, and measuring one instantly gives you information about the other. It challenges our traditional notions of space and time and opens up exciting realms in technology and science!', additional_kwargs={}, response_metadata={}, id='run-3b5dd724-f1e3-4d30-b837-6a828d62ebd3-0', usage_metadata={'input_tokens': 24, 'output_tokens': 438, 'total_tokens': 462})

Streamingโ€‹

Real-time token streaming example:

for chunk in llm.stream(messages):
print(chunk.content, end="", flush=True)
Quantum physics, also known as quantum mechanics, is the branch of physics that deals with the behavior of very small particles, like atoms and subatomic particles (electrons, protons, etc.). Here are some key concepts explained simply:

1. **Wave-Particle Duality**: Particles can behave both like particles and waves. For example, electrons can show interference patterns (a wave property) but also can be detected as distinct particles.

2. **Quantization**: Energy levels in atoms are quantized, meaning an electron can only exist in specific energy levels, not in between. When an electron jumps between these levels, it absorbs or emits a specific amount of energy (usually in the form of light).

3. **Uncertainty Principle**: Proposed by Werner Heisenberg, this principle states that you cannot precisely know both the position and momentum of a particle at the same time. The more accurately you know one, the less accurately you can know the other.

4. **Superposition**: Particles can exist in multiple states at once until they are observed or measured. For example, a particle can be in multiple places at the same time.

5. **Entanglement**: When two particles become entangled, the state of one particle is directly related to the state of another, no matter the distance between them. Changing the state of one instantly affects the other.

6. **Probability**: Instead of giving exact predictions, quantum physics deals with probabilities. It can tell you how likely it is for a particle to be found in a certain state or position.

In summary, quantum physics challenges our classical intuition and introduces a world where particles can behave in strange and non-intuitive ways, governed by probabilities rather than certainties.

API referenceโ€‹

For full documentation of all ChatLLM7 parameters and methods, see the API reference.

Key configuration options:

  • base_url: API endpoint (default: https://api.llm7.io/v1)
  • model_name: Model version selector (see the models list)
  • temperature: Creativity control (0.0-2.0)
  • max_tokens: Response length limit
  • streaming: Enable/disable real-time streaming

Was this page helpful?