Skip to content

Instantly share code, notes, and snippets.

View koganei's full-sized avatar

Marc Khoury koganei

View GitHub Profile
@koganei
koganei / main.py
Created May 5, 2023 21:03
Websocket Support for Haystack Agent
View main.py
import asyncio
import sys
import threading
from typing import Any
import json
import os
import logging
from fastapi import FastAPI, WebSocket, BackgroundTasks, WebSocketDisconnect
from fastapi.responses import HTMLResponse
from functools import partial
@koganei
koganei / CustomAgent.py
Last active April 16, 2023 15:52
Adding Post-Processing Pipeline to Haystack Agents
View CustomAgent.py
class CustomAgent(Agent):
# Post-Processing Pipeline
def __init__(self, **kwargs):
super().__init__(**kwargs)
def add_post_processing_pipeline(self, pipeline):
self.post_processing_pipeline = pipeline
self.callback_manager.on_agent_finish += self.on_result_post_process
@koganei
koganei / haystack-agent.py
Created April 14, 2023 14:56
Using a langchain tool in a Haystack agent
View haystack-agent.py
def create_wolfram_alpha_tool():
from haystack.agents import Tool
from walpha_tool.tool import WolframAlphaNode
node = WolframAlphaNode()
return Tool(name="WolframAlpha",
pipeline_or_node=node,
description="A wrapper around Wolfram Alpha. " # Taken verbatim from the langchain code, could be done automatically somehow
"Useful for when you need to answer questions about Math,"
"Science, Technology, Culture, Society and Everyday Life."
View ExtractiveQAWithPromptNodePipeline.py
from typing import Optional
# from haystack.nodes.question_generator.question_generator import QuestionGenerator
from haystack.nodes.retriever.base import BaseRetriever
from haystack.nodes import PromptNode, Shaper, TopPSampler
from haystack.pipelines.base import Pipeline
from haystack.pipelines.standard_pipelines import BaseStandardPipeline
class ExtractiveQAWithPromptNodePipeline(BaseStandardPipeline):
"""
@koganei
koganei / import-map-generation.md
Created March 17, 2023 16:34
ChatGPT generation of an import map tool
View import-map-generation.md

USER

Hi, can you give me the javascript code that will generate an import map for a given package.json so that code works in web browsers without any kind of building?

ASSISTANT

Certainly! Below is a JavaScript code snippet that generates an import map for a given package.json file. This code assumes that the dependencies in the package.json are already downloaded and placed in a folder named node_modules within your project directory, and it generates an import map compatible with native ES modules in web browsers without requiring a build step.

const fs = require("fs");

function generateImportMap(packageJsonPath) {
View unlockanimation.js
import $ from 'jquery';
import { angular } from './../../js/base';
import _ from 'lodash';
class unlockAnimation {
constructor($element, $rootScope) {
this.$rootScope = $rootScope;
this.listeners = {
click: this.onClick.bind(this),
@koganei
koganei / test.md
Last active August 29, 2015 14:19
View test.md

[test]('javascript:return false;')

@koganei
koganei / fizzbuzz.clj
Last active August 29, 2015 14:10
Haskell & Clojure Fizzbuzz
View fizzbuzz.clj
(defn fizz-buzz []
(loop [i 1]
(if (<= i 100)
(do
(if (and (= (rem i 3) 0) (= (rem i 5) 0))
(println "fizzbuzz")
(if (= (rem i 3) 0)
(println "fizz")
(if (= (rem i 5) 0)
(println "buzz")
@koganei
koganei / app.js
Created August 5, 2014 17:04
AngularJS DB Interface Layer
View app.js
/**
* The idea is to expose an interface from the app side that a service can fulfill
*/
angular.module('myapp', ['apiservice'])
/**
* We load the service that fulfills the interface through a config on the app side
*/
.factory('config', function(
@koganei
koganei / poemsApiService.js
Last active August 29, 2015 14:04
An attempt to find the best way to structure a Restangularized API service
View poemsApiService.js
(function() {
'use strict';
/**
* the poemsApi Service. Restangular has all the functions you would expect from an
* API service, so we return the Restangular resource object.
*
* @service poemsApi
* @param Restangular bower install restangular
* @return service object