Skip to content

Commit

Permalink
ais: improving thoghts
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Dec 22, 2023
1 parent 3026d14 commit fd54663
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ object Chain {

val chainDesc =
p"""
The Chain thought enable sequential linking of multiple reasoning processes.
- Facilitates the flow of reasoning from one thought to another.
- Ensures coherence and logical progression in the reasoning chain.
- Allows complex reasoning to be broken down into manageable segments.
The Chain thought enable sequential linking of multiple reasoning processes.
- Facilitates the flow of reasoning from one thought to another.
- Ensures coherence and logical progression in the reasoning chain.
"""
}
import Chain._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import kyo.llm.ais._

@desc(
p"""
The Constrain thought is a tool for applying specific constraints to the AI's reasoning process.
- The `Apply specific constraints to the value generation` field, defined as a string literal type, outlines the nature of the constraints that should govern the AI's thought generation.
- The `value` is the main focus where the AI applies the defined constraints during its reasoning or output generation.
- This mechanism is instrumental in guiding the AI to produce results within specific parameters or conditions, enhancing the relevance and precision of the output.
- Example: Constrain["Must be within ethical guidelines", EthicalReasoning] would direct the AI to ensure that the reasoning adheres to ethical guidelines.
The Constrain thought applies specific constraints to the AI's reasoning.
- Outlines constraints in the 'Apply specific constraints to the value generation' field.
- 'value' is where the AI applies these constraints in its process.
- Aims to enhance output precision and relevance.
- Example: Constrain["Adhere to ethical guidelines", EthicalReasoning] guides the AI to follow ethical standards.
"""
)
case class Constrain[C <: String, T](
`Apply specific constraints to the value generation`: C,
`Apply specific constraints`: C,
value: T
)
10 changes: 4 additions & 6 deletions kyo-llm/shared/src/main/scala/kyo/llm/thoughts/meta/Desc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import kyo.llm.ais._

@desc(
p"""
The Desc thought is designed to encapsulate a thought along with a user-defined description.
- 'desc' is a string literal type that acts as a label or a brief explanation of the thought process.
- 'value' is the actual thought or process that needs to be generated or executed.
- This class guides the LLM to focus on generating the 'value' based on the context provided by 'desc'.
- Example user code that generates this thought Desc["brainstorm something", Chain[Creative, Critical]] indicates
that the LLM should engage in a creative and critical thought chain under the theme of 'brainstorm something'.
The Desc thought pairs a user-defined description with a thought.
- 'desc': A label or brief explanation as a string literal.
- 'value': The actual thought or process to generate.
- Example: Desc["brainstorm", Chain[Creative, Critical]] guides the LLM for a brainstorming thought process.
"""
)
case class Desc[D <: String, T](desc: D, value: T)
10 changes: 5 additions & 5 deletions kyo-llm/shared/src/main/scala/kyo/llm/thoughts/meta/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import kyo.llm.ais._

@desc(
p"""
The Gen thought is structured to facilitate the generation of a specific outcome based on a given thought process.
- The 'thought' field represents the thought process or reasoning approach that the AI should use.
- The 'value' field is the specific outcome or result that should be generated using the specified thought process.
- This thought encourages the AI to apply a particular reasoning method (as defined in 'thought') to produce a desired output (as specified in 'value').
- Example: Gen[Analysis, "Potential solutions to a problem"] would direct the AI to use analytical reasoning to generate potential solutions to the given problem.
The Gen thought links a specific reasoning approach with a desired outcome.
- 'thought': The reasoning method to be applied.
- 'value': The outcome to be generated.
- Guides the AI in applying the chosen reasoning to produce the specified result.
- Example: Gen[Analysis, "Solutions"] uses analysis to generate solutions.
"""
)
case class Gen[T, U](
Expand Down
22 changes: 7 additions & 15 deletions kyo-llm/shared/src/main/scala/kyo/llm/thoughts/meta/Init.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@ import kyo.llm.ais._

@desc(
p"""
The Init thought sets foundational guidelines for the LLM's reasoning process, especially in adhering to the JSON schema.
- **Crucially, the LLM must never generate arbitrary fields and should strictly follow the provided JSON schema.**
- This thought ensures that 'value' represents specific, predefined thoughts or reasoning steps.
- Acts as a blueprint for integrating thoughts into a logical and schema-compliant reasoning pathway.
- Aims for well-structured responses that align with the user's intent and adhere to JSON formatting rules.
- Fields focus on reflecting upon past errors and strategizing to avoid them, especially in maintaining JSON schema integrity.
- Example: A 'value' containing Chain[Analysis, Synthesis] should be elaborated in accordance with the schema, without adding extraneous fields.
- **The LLM is required to ensure compliance with the JSON schema at all times.**
The Init thought guides the LLM in structuring reasoning to align with JSON schema.
- Emphasizes schema compliance and logical reasoning.
- Aids in reflecting on and improving from past outputs.
- Ensures strict adherence to formatting rules.
"""
)
case class Init[T](
`Have you failed at previous attempts to generate this json`: Boolean,
`Analysis of the previous failures`: String,
`Strategy to avoid another failure`: String,
`Elaborate on the strategy to avoid failures`: String,
`The generated json can't have new line characters`: Boolean,
`I understand I can't use new lines`: Boolean,
`Strictly adhere to the provided JSON schema without adding arbitrary fields`: Boolean,
`Reflect on past JSON errors`: Boolean,
`Strategy for JSON schema compliance`: String,
`Adhere strictly to JSON schema and formatting`: Boolean,
value: T
)
38 changes: 19 additions & 19 deletions kyo-llm/shared/src/main/scala/kyo/llm/thoughts/meta/Select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@ object Select {

val SelectDesc =
p"""
The Select thought facilitates the LLM's choice in focusing on particular reasoning processes.
- Enables selective expansion on specific thoughts based on relevance and significance.
- Provides flexibility in the reasoning pathway, allowing the LLM to prioritize and delve deeper into chosen thoughts.
- Encourages a targeted approach to reasoning, ensuring a more efficient and relevant output.
- The use of 'Option' in each thought or process allows for dynamic selection based on the context of the conversation.
The Select thought allows the LLM to focus on specific reasoning processes.
- Facilitates choice and prioritization of thoughts for relevance.
- Enables a flexible and targeted reasoning approach.
- Uses optional fields for dynamic thought selection based on context.
"""
}

import Select._

@desc(SelectDesc)
case class Select[A, B](
`First thought or process`: Option[A],
`Second thought or process`: Option[B]
`First thought`: Option[A],
`Second thought`: Option[B]
)

@desc(SelectDesc)
case class Select3[A, B, C](
`First thought or process`: Option[A],
`Second thought or process`: Option[B],
`Third thought or process`: Option[C]
`First thought`: Option[A],
`Second thought`: Option[B],
`Third thought`: Option[C]
)

@desc(SelectDesc)
case class Select4[A, B, C, D](
`First thought or process`: Option[A],
`Second thought or process`: Option[B],
`Third thought or process`: Option[C],
`Fourth thought or process`: Option[D]
`First thought`: Option[A],
`Second thought`: Option[B],
`Third thought`: Option[C],
`Fourth thought`: Option[D]
)

@desc(SelectDesc)
case class Select5[A, B, C, D, E](
`First thought or process`: Option[A],
`Second thought or process`: Option[B],
`Third thought or process`: Option[C],
`Fourth thought or process`: Option[D],
`Fifth thought or process`: Option[E]
`First thought`: Option[A],
`Second thought`: Option[B],
`Third thought`: Option[C],
`Fourth thought`: Option[D],
`Fifth thought`: Option[E]
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import kyo.llm.ais._

@desc(
p"""
The Analysis thought breaks down the input into more manageable parts.
- Dissects the input into fundamental elements.
- Explores connections among elements.
- Critically assesses the validity and logic.
- Relevant techniques: Data Decomposition, Logical Analysis.
The Analysis thought breaks down the input into more manageable parts.
- Dissects the input into fundamental elements.
- Explores connections among elements.
- Critically assesses the validity and logic.
- Relevant techniques: Data Decomposition, Logical Analysis.
"""
)
case class Analysis(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import kyo.llm.ais._

@desc(
p"""
The Contextualization thought involves placing the input within a broader framework.
- Assesses the relationship of input to previous discussions or knowledge.
- Identifies broader context relevant to the input.
- Considers implications of external factors.
- Relevant techniques: Context Analysis, Pattern Recognition.
The Contextualization thought involves placing the input within a broader framework.
- Assesses the relationship of input to previous discussions or knowledge.
- Identifies broader context relevant to the input.
- Considers implications of external factors.
- Relevant techniques: Context Analysis, Pattern Recognition.
"""
)
case class Contextualization(
`Determine the core message or question in the input`: String,
`Assess how the current input relates to previous discussions or knowledge`: String,
`Identify the broader context or background relevant to the input`: String,
`Consider the implications of external factors or related concepts`: String
`Consider the implications of external factors or related concepts`: String,
`Identify any ambiguous or unclear aspects that need further clarification`: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,17 @@ import kyo.llm.ais._

@desc(
p"""
The Creative thought encourages creative and divergent thinking in AI processes.
- Draws on concepts from creative problem solving and design thinking.
- Utilizes divergent thinking models from cognitive psychology.
- Applies ideation techniques and lateral thinking for novel idea generation.
- Relevant techniques: TRIZ, SCAMPER, Mind Mapping.
- Each 'Elaborate' field prompts the AI to provide detailed explanations and insights, enhancing the depth of the creative process.
The Creative thought fosters innovation and divergent thinking in AI.
- Combines creative problem solving with design thinking.
- Encourages lateral thinking and ideation for novel concepts.
- Includes 'Elaborate' fields for in-depth explanations, enriching creativity.
"""
)
case class Creative(
brainstormIdeas: BrainstormIdeas,
explorePossibilities: ExplorePossibilities,
synthesizeConcepts: SynthesizeConcepts
)

case class BrainstormIdeas(
`Generate a list of creative ideas and concepts`: String,
`Elaborate on the creative ideas and concepts`: String,
`Apply lateral thinking to explore new perspectives`: String,
`Elaborate on the new perspectives`: String
)

case class ExplorePossibilities(
`Consider alternative solutions and challenge existing assumptions`: String,
`Elaborate on alternative solutions and challenged assumptions`: String,
`Assess the feasibility and impact of different ideas`: String,
`Elaborate on the feasibility and impact assessment`: String
)

case class SynthesizeConcepts(
`Integrate diverse ideas into coherent concepts`: String,
`Elaborate on the integration of ideas into concepts`: String,
`Create innovative approaches or solutions`: String,
`Elaborate on the innovative approaches or solutions`: String
`Reflect on the user's intent`: String,
`Apply lateral thinking for new perspectives`: String,
`Elaborate on new perspectives`: String,
`Consider alternative solutions`: String,
`Create innovative approaches`: String,
`Elaborate on innovative solutions`: String
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kyo.llm.thoughts.reasoning

import kyo.llm.ais._

@desc(
p"""
Empathy thought in AI reasoning focuses on understanding emotions and social contexts.
- Interprets emotional cues in text.
- Deepens insight into emotional expressions.
- Considers social and cultural contexts.
- Reflects on the influence of social norms and values.
"""
)
case class Empathy(
`Interpret emotional cues in text`: String,
`Gain insight into emotional expressions`: String,
`Understand social and cultural contexts`: String,
`Reflect on social norms and values`: String
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import kyo.llm.ais._

@desc(
p"""
The Repair thought is used for introspection and correction following errors in the LLM's reasoning or output.
- Focuses on analyzing recent actions to identify the causes of failures.
- Aims to develop strategies to prevent similar errors in future reasoning processes.
- Encourages the LLM to critically evaluate its performance and apply corrective measures.
- This thought is crucial for the LLM's learning process, allowing it to adapt and improve over time.
- Example: If an error is detected in JSON generation, Repair directs the LLM to pinpoint the error's source and
modify its approach to ensure compliance with JSON standards.
The Repair thought guides the LLM in addressing and learning from errors.
- Analyzes causes of past failures.
- Develops strategies to prevent future errors.
- Encourages critical evaluation and adaptive learning.
"""
)
case class Repair(
`Analyze recent actions to identify failure causes`: String,
`Develop strategies to avoid similar errors`: String,
`Elaborate on the corrective measures to be applied`: String
`Identify causes of past failures`: String,
`Formulate strategies to prevent future errors`: String,
`Detail corrective measures for improvement`: String
)

This file was deleted.

Loading

0 comments on commit fd54663

Please sign in to comment.